-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type annotations enforce visibility of properties (aka private fields) #336
Comments
In your example, FOO is actually a property. If you add public modifier, it is a static final field and will be inlined properly with no warnings or issues.
|
Yep, I knew |
The visibility of the property is synthetic-public (not package-private) and the visibility of the backing field is private. You could rewrite this way and it would also work:
@SuppressWarnings(Broken.FOO)
class Broken {
@PackageScope static final String FOO = 'unchecked'
}
Update: protected would also work just fine.
Previous versions of Groovy-Eclipse did minimal processing of annotations and so there was little to no checking in scenarios like this.
|
@eric-milles shouldn't this match CLI behaviour? Does it really make sense for one IDE to need entirely different code? |
The error is emitted by Eclipse JDT, not the compiler. If you leave off the modifier, you are also getting a method generated. Do you really need getFOO() to access the constant value? I would say it is a better practice to require developers to use public in the case of static finals. |
Not sure where the error is coming from matters exactly? We're talking about something that is apparently syntactically valid in both Java & Groovy but groovy-eclipse throws an error on. |
Groovy-Eclipse is an integration of Groovy into the Eclipse JDT model/tooling. All the checks you see under Window > Preferences > Java > Compiler > Errors/Warnings are above and beyond Groovyc. There are certain gaps between this tooling and plain CLI Groovyc that simply cannot be closed due to the nature of Groovy-Eclipse. When annotations were added to the Java model, the modifier checking became active. But so too did null checking (@nonnull, @nullable, etc.) and other annotation-based features.
Core Groovy has discussed respecting private visibility but has reserved such a change for a major version. However, static compilation likely checks visibility in this case and many others. If you get used to treating private as private today, you will be well prepared for static compilation and future Groovy versions.
|
Minimal test case:
Works in maven CLI builds and other IDEs
The text was updated successfully, but these errors were encountered: