question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated code has "Parameter is hiding a field" warnings all over

See original GitHub issue

The below is the generated code for one of my components:

  public CoreModule_ProvideUpdateCheckerFactory(
      Provider<Settings> aSettingsProvider,
      Provider<UpdateChecker.UpdateCallback> aUpdateCallbackProvider,
      Provider<String> aVersionProvider) {
    assert aSettingsProvider != null;
    this.aSettingsProvider = aSettingsProvider;
    assert aUpdateCallbackProvider != null;
    this.aUpdateCallbackProvider = aUpdateCallbackProvider;
    assert aVersionProvider != null;
    this.aVersionProvider = aVersionProvider;
  }

This occurs for just about all generated code.

This code causes a warning for each of the parameters to the tune of:

The parameter SettingsProvider is hiding a field from type CoreModule_ProvideUpdateCheckerFactory

This is caused by the formal parameter having the same name as the field in the class. The code works correctly thanks to qualification using this.. Could the code generation be change to set a prefix or suffix or something on the formal arguments to avoid this warning?

Warning for variable shadowing is default in Eclipse AFAICT.

Dagger version 2.10, Java 8.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
gk5885commented, Apr 18, 2017

I think your best bet is to just deal with this on the eclipse end. See this Stack Overflow question and this bug. Apparently Eclipse runs afoul of quite a few code generators…

2reactions
gk5885commented, Apr 18, 2017

We hold the generated code to exactly that standard, but only for javac. Eclipse adds a whole bunch of other non-standard checks that change from release to release. We can’t possibly track every new check added by every IDE or static analysis tool, so we drew the line at the standard compiler. I don’t think that’s going to change any time soon, especially given that this is a style check and not a correctness issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Troubleshooting "The type parameter T is hiding the ...
The warning appears at 'T' in 'A' and reads: "The type parameter T is hiding the type T". The weird part is that...
Read more >
Compiler warning "is hiding a field" given for static inner class
The language spec tolerates field hiding. As a courtesy we will warn the user if the optional diagnosis for field hiding is enabled....
Read more >
Warning Options (Using the GNU Compiler Collection (GCC))
Warnings are diagnostic messages that report constructions that are not inherently erroneous but that are risky or suggest there may have been an...
Read more >
C# preprocessor directives - Microsoft Learn
Learn the different C# preprocessor directives that control conditional compilation, warnings, nullable analysis, and more.
Read more >
Predefined Annotation Types - Java™ Tutorials
The Java Tutorials have been written for JDK 8. ... The compiler generates a warning whenever a program uses a method, class, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found