Community
Participate
Working Groups
Eclipse 3.3. In the following code, the detection of "assignment with no effect" does not flag the problem in the start method. Removing the reference to the static class causes the detection to work. public class DirectorActivator implements BundleActivator { public static final String PI_DIRECTOR = "org.eclipse.equinox.prov.director"; //$NON-NLS-1$ public static BundleContext context; public void start(BundleContext ctx) throws Exception { DirectorActivator.context = context; } public void stop(BundleContext ctx) throws Exception { DirectorActivator.context = null; } }
Created attachment 76783 [details] Proposed fix Philippe, please review. This patch reports an assignment with no effect when the qualified name simply refers to a static field using ClassName.FieldName.
Created attachment 76784 [details] Regression tests
What about a situation where the qualified name has the package prefix ? e.g. some.package.ClassName.field
The proposed patch works fine. package p; public class X { public static Object context; public void start(Object ctx) throws Exception { p.X.context = context; } } ---------- 1. WARNING in D:\tests_sources\p\X.java (at line 6) p.X.context = context; ^^^^^^^^^^^^^^^^^^^^^ The assignment to variable context has no effect ----------
Looks good to me. Maxime pls proceed.
Fix is OK in that it addresses most common cases involving static fields. Added a few more tests that check variations (package, inner class, swapping the lhs and the rhs) and document a limitation (there are cases for which a static analysis could prove that the runtime type of a variable equates a defined one, in which case the access to the static fields of the said variable would provably point to a well defined field, and we could report additional warnings - see AssignmentTest#48, which is inactive).
Created attachment 80549 [details] Fix + test cases Fixed a typo in comments and added more tests.
Released for 3.4 M3
Verified for 3.4M3 using I20071029-0010 build.