Community
Participate
Working Groups
I20070828-0800 When the 'Unused local or private member' compiler option is enabled, unused public members of private nested classes could also be flagged as unused (need to check the whole enclosing top-level type for references). Unused public members are already detected inside anonymous classes. public class Try { private static class Nested { public void unused1() {} // not found } public static void main(String[] args) { new Nested().hashCode(); new Runnable() { public void run() {} public void unused2() {} // found to be unused }; } }
The trick is that it could be used from outside, even though this would cause a compile error (not accessible member), where in the case of a local type member there would be no possible way to access it (even incorrectly).
> The trick is that it could be used from outside, even though this would cause a > compile error (not accessible member), ... But that's also the case for unused private members of top-level classes: public class Try { private static void unused3() {} } => Method is also unused, although there could be a reference to Try.unused3() somewhere, with an equivalent "... is not visible" error.
You're right. I need to look into it.
Srikanth - pls have a look
(In reply to comment #1) > The trick is that it could be used from outside, even though this would cause a > compile error (not accessible member), where in the case of a local type member > there would be no possible way to access it (even incorrectly). In any event, the message we issue says "never used locally" or "never read locally" etc, so it should be OK. I have a fix for this that solves the problem. However, there are about ~320 "failures" in the test suite run - I need to validate that all the changed diagnostics are legit and remaster the expected output. Fun !
Created attachment 124945 [details] Proposed fix and tests
Created attachment 125106 [details] Proposed fix and tests Revised patch to warn on unused interface method specifications too.
Created attachment 125569 [details] Proposed patch and testcases Srikanth, please take a look at this patch. A few of the test changes in MethodVerifyTest and NegativeTest showed problems. This patch tags all anonymous types as used since we do not seem to detect when an anonymous type really is used & it also tags inherited interface methods as used (not just the concrete implementation).
(In reply to comment #8) > Created an attachment (id=125569) [details] [...] > This patch tags all anonymous types as used since we do not seem to detect when > an anonymous type really is used & it also tags inherited interface methods as > used (not just the concrete implementation). Did you mean to say not just the concrete implementation being enclosed by a private type ? The patch looks good.
Yes, not only the concrete method needs to be tagged but the interface methods also need to be tagged. Released fix and tests for 3.5M6
Verified for 3.5M6 using I20090310-0100.