Fixed
Status Update
Comments
pa...@gmail.com <pa...@gmail.com> #2
I'd like to see this built in to lint as well, but there is an existing inspection that already does this in Android Studio (presumably inherited from IntelliJ), albeit in a non-obvious location for Android developers.
J2ME Issues -> Private member access between outer and inner classes
J2ME Issues -> Private member access between outer and inner classes
ja...@gmail.com <ja...@gmail.com> #3
@Paul Cool! Didn't know about that one.
Funny enough, in IntelliJ IDEA 16 there's a new inspection that's enabled by default that's fundamentally at odds with that inspection and this lint check: Java > Visibility issues > Access can be tightened. It prompts for _all_ visibility reductions! I'm going to file a YouTrack for adding an option similar to this lint check.
Funny enough, in IntelliJ IDEA 16 there's a new inspection that's enabled by default that's fundamentally at odds with that inspection and this lint check: Java > Visibility issues > Access can be tightened. It prompts for _all_ visibility reductions! I'm going to file a YouTrack for adding an option similar to this lint check.
ta...@gmail.com <ta...@gmail.com> #5
I see that this lint check is enabled in Android Studio 2.1 preview. It may be coming from IntelliJ side.
But I see that it shows the same error for private static final String fields. If it is private static final, compiler should inline that value right? So there shouldn't be synthetic accessor, right?
But I see that it shows the same error for private static final String fields. If it is private static final, compiler should inline that value right? So there shouldn't be synthetic accessor, right?
pa...@gmail.com <pa...@gmail.com> #6
#4 yes, that should be the case, but only if the value is a compile-time constant, so LOG = getLogger() won't be inlined and accessor generated. Best is to check a few examples: find your .class file and run a decompiler (e.g. JAD) on it to see the accessors.
tn...@google.com <tn...@google.com>
tn...@google.com <tn...@google.com> #7
Implemented in 3.2 canary 11 (but note that the check is off by default; enable the id SyntheticAccessor .)
Description
A lint check could detect these situations and recommend that the private method/ctor had its visibility increased to package-scope to avoid the need for the synthetics.
Specifically, for this test code:
public class Test {
public static void main(String... args) {
TestInner inner = new TestInner();
inner.run();
inner.bye();
}
private static final class TestInner implements Runnable {
private TestInner() {}
@Override public void run() {
System.out.println("Hello, world!");
}
private void bye() {
System.out.println("Goodbye, world!");
}
}
}
The `new TestInner()` should be flagged and `inner.bye()` should be flagged.
If you wanted, you could instead flag the private constructor and private method directly and then list the call sites which are accessing them from outside the private scope, but I think that would be harder to do.