Inspection Gadgets...

Got this when doing an auto-fix of Remove Redundanct Initializer...

java.lang.NullPointerException

at com.intellij.codeInspection.t.r$2.run(r$2.java:0)

at com.intellij.openapi.application.b.b.runWriteAction(b.java:300)

at com.intellij.codeInspection.t.r$1.run(r$1.java:2)

at com.intellij.openapi.command.b.a.executeCommand(a.java:39)

at com.intellij.codeInspection.t.r.a(r.java:6)

at com.intellij.codeInspection.t.r.actionPerformed(r.java:47)

at com.intellij.openapi.actionSystem.b.o$b_.actionPerformed(o$b_.java:4)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at com.intellij.openapi.actionSystem.b.o.fireActionPerformed(o.java:61)

at com.intellij.ui.b.a.h.doClick(h.java:88)

at com.intellij.ui.b.a.h.access$300(h.java:22)

at com.intellij.ui.b.a.h$a_.mouseReleased(h$a_.java:2)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at com.intellij.ide.s.a(s.java:25)

at com.intellij.ide.s.dispatchEvent(s.java:107)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

9 comments
Comment actions Permalink

Here's a simple class that throws the exception when trying to auto remove the unused assignments.



Attachment(s):
TestInspect.java
0
Comment actions Permalink

er, let's try that one more time, but this time I'll save it before attaching it!



Attachment(s):
TestInspect.java
0
Comment actions Permalink

I'll give it a look.

--Dave

0
Comment actions Permalink

BTW - on a separate note, what is the inspection about that offers to make protected static methods private in Final classes? Surely this is only acceptable if I don't have other classes in the same package that are calling the method in that class?

Protected Member In Final Class "This inspection reports any instances of members being declared protected in classes that are declared final. Such members may be declared private."

Actually, thinking about it, this may just be a bug that wasn't excluding static methods from the members that it offered to make private, although can't protected fields also be accessed by other classes in the same package?

0
Comment actions Permalink


Good eye. I keep forgetting that protected members can be accessed anywhere package-visible members can be, probably because I think that semantics is a really stupid mistake on the part of the Java designers. I'll change the fix to make the members package-visible, which should be safe. Thanks for catching that one.

--Dave

0
Comment actions Permalink

here's another one I'm getting in a simple XmlPrettyPrinting class I wrote...

lines 105 and 120 are both flagged as their values not being used, but this seems to be ignoring the fact that they're both in a loop and that the values will be used next time around.



Attachment(s):
XmlPrettyPrinter.java
0
Comment actions Permalink

1) The inspection you're triggering is actually a built-in one, not part of InspectionGadgets.
2) The error at line 105 is actually triggered correctly, as the variable you are writing will be overwritten in the next loop iteration before it is used, making the assignment pointless.
3) The error at line 120 is an IDEA bug. You should try to distill it and post a tracker item.

--Dave

0
Comment actions Permalink

Actually it was my bad on 120 too!

It should have read
= INDENT_SIZE ? indent - INDENT_SIZE : indent; not indent = indent >= INDENT_SIZE ? indent -= INDENT_SIZE : indent; ]]>

0
Comment actions Permalink

or, of course, better yet...

= INDENT_SIZE) indent -= INDENT_SIZE; ]]>

Don't know what the Hell I was thinking with either of the earlier versions.

0

Please sign in to leave a comment.