Community
Participate
Working Groups
Build 3.1rc3 The following program should not raise a warning for unnecessary instanceof operation. public class X { void foo() { System.out.println(null instanceof Object); } }
This one is simple to address, but this one is not: public class X { void foo() { Object o = null; System.out.println(o instanceof Object); } }
Would vote to only address the obvious case (original report).
Created attachment 23727 [details] Patch for InstanceOfExpression
Non critical for 3.1, will consider for 3.1.1
Created attachment 23728 [details] Patch for CastTest
Fixed in 3.1 maintenance branch
Verified in 3.2 M1 with build I20050808-2000. As announced, the case of Comment #1 is not addressed.
Verified using M20050923-1430 for 3.1.1
*** Bug 111026 has been marked as a duplicate of this bug. ***
There still exists a problem as you mentioned in Comment #1. Is there another bug open to correct that error? What is the reasoning behind warning the user of an unnecessary instanceof? Maybe it shouldn't warn the user at all because it very well may be necessary, as the code below shows. I think the JDT should not warn me rather than incorrectly warn me. Object o = null; System.out.println(o instanceof Object); ^^^^^^^^^^^^^^^^^^^
Never warning on instanceof checks would be harsh... but now we have some support for null ref analysys, we should consider some cross fertilization. Maxime - pls enter a separate PR to track this enhancement.