References to nested enum constants in switch statement are not counted when...
Eclipse Plugin to find unused Java code
Brought to you by:
spj
References to nested enum constants in switch statement are not counted when assessing for visibility, but should be.
In the OuterClass.java below, UCDetector flags the line with "enum InnerEnum" with "Change visibility of Enum "OuterClass.InnerEnum" to private - May cause compile errors!". However, the enum constants are referenced by the switch statement in the neighbouring class (see UndetectedReferencesToNestedEnum.java).
OuterClass.java
package philip.debug.ucdetector;
public final class OuterClass {
enum InnerEnum {
/*^^^^^^^^^^^*/
CONSTANT1,
CONSTANT2;
}
static InnerEnum getSomeEnum() {
return InnerEnum.CONSTANT1;
}
}
UndetectedReferencesToNestedEnum.java:
package philip.debug.ucdetector;
public final class UndetectedReferencesToNestedEnum {
public static void main(final String[] args) {
switch (OuterClass.getSomeEnum()) {
case CONSTANT1:
System.out.println("Constant One");
break;
default:
System.out.println("Constant Two");
break;
}
}
}
P.S.: Thank you for this valuable tool!
Anonymous
Hallo Philip,
thanks for your detailed Bug Reports.
I have no plans at the moment to do more UCDetector releases.
Jörg