[ANN] InspectionGadgets 0.0.6 released


Announcing version 0.0.6 of the InspectionGadgets plugin, available via the PluginManager
or at http://www.intellij.org/twiki/bin/view/Main/InspectionGadgets.

Changes in version 0.0.6

New Inspections

Unnecessary fully qualified name(*)
Method overloads method of superclass
Use of obsolete collection type
Infinite loop statement
For loop where update or condition doesn't use loop variable
For loop with missing components
Redundant field initialization(*)
Unused label
Serializable class with unconstructable ancestor

(Inspections marked with * include quickfixes)

plus lots of bugfixes

--Dave "I wanna see that download counter spin!" Griffith

32 comments

Hi,

On 2003/10/28 15:06, Dave Griffith wrote:

Announcing version 0.0.6 of the InspectionGadgets plugin, available via the PluginManager
or at http://www.intellij.org/twiki/bin/view/Main/InspectionGadgets.


Great stuff!
And here's the first bug report;-) I got an exception typing "try"
inside a method. This bug was also present in version 0.0.5, but just
when I got around to report it, you announced 0.0.6. But I checked and
the NPE is also thrown in the new version.

Bas

2003-10-28 15:14:56,878 ERROR -
emon.impl.LocalInspectionsPass - Exception happened in local inspection
tool: 'catch' generic class
2003-10-28 15:14:56,888 ERROR -
emon.impl.LocalInspectionsPass - IntelliJ IDEA (Aurora) Build #957
2003-10-28 15:14:56,888 ERROR -
emon.impl.LocalInspectionsPass - JDK: 1.4.2
2003-10-28 15:14:56,888 ERROR -
emon.impl.LocalInspectionsPass - VM: Java HotSpot(TM) Client VM
2003-10-28 15:14:56,888 ERROR -
emon.impl.LocalInspectionsPass - Vendor: Sun Microsystems Inc.
2003-10-28 15:14:56,888 ERROR -
emon.impl.LocalInspectionsPass - OS: Windows 2000
2003-10-28 15:14:56,888 ERROR -
emon.impl.LocalInspectionsPass - Last Action: EditorBackSpace
2003-10-28 15:14:56,908 ERROR -
emon.impl.LocalInspectionsPass - Exception happened in local inspection
tool: 'catch' generic class
java.lang.NullPointerException
at
com.siyeh.ig.psiutils.ExceptionUtils.calculateExceptionsThrown(ExceptionUtils.java:56)
at
com.siyeh.ig.errorhandling.CatchGenericClassInspection$CatchGenericClassVisitor.visitTryStatement(CatchGenericClassInspection.java:46)
at com.intellij.psi.impl.source.d.a.bo.accept(bo.java:60)
at com.intellij.psi.impl.source.d.s.acceptChildren(s.java:32)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java:1)
at
com.intellij.psi.JavaElementVisitor.visitCodeBlock(JavaElementVisitor.java:37)
at com.intellij.psi.impl.source.d.a.br.accept(br.java:1)
at com.intellij.psi.impl.source.o.acceptChildren(o.java:5)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java:1)
at
com.intellij.psi.JavaElementVisitor.visitMethod(JavaElementVisitor.java:158)
at com.intellij.psi.impl.source.bb.accept(bb.java:59)
at
com.siyeh.ig.StatementInspection.checkMethod(StatementInspection.java:55)
at com.intellij.codeInsight.a.a.w.a(w.java:34)
at com.intellij.codeInsight.a.a.bj$1.run(bj$1.java:2)
at com.intellij.openapi.application.a.b.runReadAction(b.java:252)
at com.intellij.codeInsight.a.a.bj.a(bj.java:20)
at com.intellij.codeInsight.a.a.bj.access$100(bj.java:16)
at com.intellij.codeInsight.a.a.bj$0.run(bj$0.java:0)
at com.intellij.progress.c.a(c.java:9)
at com.intellij.codeInsight.a.a.bj.run(bj.java:1)

0

Yahoo! Been looking forward to this for a while! (Thanks for fixing my
'redundant import' bug.)

Two small bug reports and another couple of exceptions:
Bug 1: If I import com.n.Class1 to access a public static inner class
(e.g. Class1.Inner) then Class1 is marked as redundant if only the inner
class is used. Also, unused import don't have text marked in grey - to
be clearer, given two files a/Test.java and b/Test2.java

a/Test.java
package a;
import java.util.Map; // Really redundant, text is grey
import b.Test2; // b.Test2 marked as redundant

public class Test {
Test2.Test3 test3;
}

b/Test2.java
package b;
public class Test2 {
public static class Test3 {}
}

Bug 2:
java.awt.Window.java (read-only, not in my project) is showing every
import as unused. Works fine for, e.g. java.util.regex.Pattern.

Exceptions:
Both exceptions occurred when manually typing imports for a test case
for the bug report!
Exception 1:
Error message: Exception happened in local inspection tool: Redundant import
java.lang.NullPointerException
at
com.siyeh.ig.imports.RedundantImportInspection$RedundantImportVisitor.visitClass(RedundantImportInspection.java:62)
at com.intellij.psi.impl.source.r.accept(r.java:250)
at com.siyeh.ig.ClassInspection.checkClass(ClassInspection.java:22)
at com.intellij.codeInsight.a.a.w.a(w.java:42)
at com.intellij.codeInsight.a.a.bj$1.run(bj$1.java:2)
at com.intellij.openapi.application.a.b.runReadAction(b.java:252)
at com.intellij.codeInsight.a.a.bj.a(bj.java:20)
at com.intellij.codeInsight.a.a.bj.access$100(bj.java:16)
at com.intellij.codeInsight.a.a.bj$0.run(bj$0.java:0)
at com.intellij.progress.c.a(c.java:9)
at com.intellij.codeInsight.a.a.bj.run(bj.java:1)

Exception 2:
Error message: Exception happened in local inspection tool: Redundant import
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1444)
at
com.siyeh.ig.imports.RedundantImportInspection$RedundantImportVisitor.visitClass(RedundantImportInspection.java:62)
at com.intellij.psi.impl.source.r.accept(r.java:250)
at com.siyeh.ig.ClassInspection.checkClass(ClassInspection.java:22)
at com.intellij.codeInsight.a.a.w.a(w.java:42)
at com.intellij.codeInsight.a.a.bj$1.run(bj$1.java:2)
at com.intellij.openapi.application.a.b.runReadAction(b.java:252)
at com.intellij.codeInsight.a.a.bj.a(bj.java:20)
at com.intellij.codeInsight.a.a.bj.access$100(bj.java:16)
at com.intellij.codeInsight.a.a.bj$0.run(bj$0.java:0)
at com.intellij.progress.c.a(c.java:9)
at com.intellij.codeInsight.a.a.bj.run(bj.java:1)

Thanks again for all your hard work,
Robbie

0

I guess I've never hit this one because I never type a "try" statement, preferring to they auto-generated by "Surround With". A fix (0.0.6.1) has been posted to the plugin site. Just hit the manager button and you'll have it.

--Dave Griffith

0

Dave Griffith wrote:

Announcing version 0.0.6 of the InspectionGadgets plugin, available via the PluginManager
or at http://www.intellij.org/twiki/bin/view/Main/InspectionGadgets.


Hmm. IDEA claims I have version 0.1 installed (status "newest"). It
won't let me install the new version or uninstall the old one. I
guess I'll have to quit IDEA, delete the plugin, and try again.

0

Thanks very much for continuing to support this, despite your 'hiatus' ;)

I found an exception when executing the quickfix to the "Unnecessary
fully qualified name". The code it was attempting to optimize was a
qualified inner class from a superclass - the qualification quite
rightly wasn't required.

java.lang.NullPointerException
at com.intellij.psi.impl.o.createImportStatement(o.java:274)
at
com.siyeh.ig.verbose.UnnecessaryFullyQualifiedNameInspection.addImpor
tIfNecessary(UnnecessaryFullyQualifiedNameInspection.java:148)
at
com.siyeh.ig.verbose.UnnecessaryFullyQualifiedNameInspection.access$2
00(UnnecessaryFullyQualifiedNameInspection.java:12)
at
com.siyeh.ig.verbose.UnnecessaryFullyQualifiedNameInspection$Unnecess
aryFullyQualifiedNameFix.applyFix(UnnecessaryFullyQualifiedNameInspection.java:6
7)
at com.intellij.codeInspection.v.n.invoke(n.java:5)
at com.intellij.codeInsight.intention.a.x$8.run(x$8.java:0)
at com.intellij.openapi.application.a.b.runWriteAction(b.java:296)
at com.intellij.codeInsight.intention.a.x$10.run(x$10.java:2)
at com.intellij.openapi.command.a.a.executeCommand(a.java:22)
at com.intellij.codeInsight.intention.a.x$0.run(x$0.java:0)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.intellij.ide.s.a(s.java:41)
at com.intellij.ide.s.dispatchEvent(s.java:62)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

0

It did that on mine too. I don't think the jar you already have on
there has the necessary info so IDEA thinks it's newer. Deleting the
jar and reinstalling via the Plugin Manager fixes it.

N.

Jonas Kvarnström wrote:

Dave Griffith wrote:

>> Announcing version 0.0.6 of the InspectionGadgets plugin, available
>> via the PluginManager
>> or at http://www.intellij.org/twiki/bin/view/Main/InspectionGadgets.


Hmm. IDEA claims I have version 0.1 installed (status "newest"). It
won't let me install the new version or uninstall the old one. I
guess I'll have to quit IDEA, delete the plugin, and try again.


0

Another exception:

java.lang.NoClassDefFoundError:
com/siyeh/ig/verbose/UnnecessaryInterfaceModifierInspection$UnnecessaryInterfaceModifersFix

at
com.siyeh.ig.verbose.UnnecessaryInterfaceModifierInspection.buildFix(UnnecessaryInterfaceModifierInspection.java:103)

at
com.siyeh.ig.BaseInspectionVisitor.registerError(BaseInspectionVisitor.java:28)

at
com.siyeh.ig.verbose.UnnecessaryInterfaceModifierInspection$UnnecessaryInterfaceModifierVisitor.visitMethod(UnnecessaryInterfaceModifierInspection.java:239)

at com.intellij.psi.impl.source.bb.accept(bb.java:59)

at
com.siyeh.ig.verbose.UnnecessaryInterfaceModifierInspection.checkMethod(UnnecessaryInterfaceModifierInspection.java:54)

at com.intellij.codeInsight.a.a.w.a(w.java:34)

at com.intellij.codeInsight.a.a.bj$1.run(bj$1.java:2)

at com.intellij.openapi.application.a.b.runReadAction(b.java:252)

at com.intellij.codeInsight.a.a.bj.a(bj.java:20)

at com.intellij.codeInsight.a.a.bj.access$100(bj.java:16)

at com.intellij.codeInsight.a.a.bj$0.run(bj$0.java:0)

at com.intellij.progress.c.a(c.java:9)

at com.intellij.codeInsight.a.a.bj.run(bj.java:1)

0

This one looks like you tried to use the plugin after downloading but before restarting. Sadly, "hot-swap" logic for plugins seems to be low on JetBrains lists.

I'll look at the others. I had thought I caught all the cases for imports and FQ names, but it looks like I missed some inner class ones.


--Dave

0

Re the bug report for Window.java - I turned off error highlighting and
turned it back on and only unused imports are highlighted. Strange ...

0

No I definitely restarted. It looked weird to me too, maybe an internal
problem in IDEA, dodgy classloader or something.

Anyway, if it pops up again I'll let you know.

N.

Dave Griffith wrote:

This one looks like you tried to use the plugin after downloading but before restarting. Sadly, "hot-swap" logic for plugins seems to be low on JetBrains lists.

I'll look at the others. I had thought I caught all the cases for imports and FQ names, but it looks like I missed some inner class ones.


--Dave


0

Another small bug - the following code gives "Parameter 'string' hides
member variable, which isn't correct because it's in a static context.

public class Test {
private String string;

private static void doSomething (String string) {
System.out.println ("string = " + string);
}
}

Keep up the good work!
R

0

Gak! I got hit with a killer:
cursor over the '==' in the class below; choose the first quickfix
(replace with 'equals'): it gets munged to !this.equals(this)

Also if I have
if (this != this)
the first quickfix proposed is "replace with 'equals'" instead of
"replace with ! .equals()"

public class Test {
public void doTest() {
if (this == this) {

}
}
}

0

That's actually an InspectionPowerPack bug, no InspectionGadgets. I'll be issuing an IPP release in a couple of days, which has this fix in it.

(that said, what is the possible use of "this == this"?)

--Dave

0

Reproducible test case! Since you're making my life easier, I'm just
trying to reciprocate ...

0

Robert Gibson wrote:

Another small bug - the following code gives "Parameter 'string' hides
member variable, which isn't correct because it's in a static context.


Well, technically the member variable 'string' isn't accessible inside
'doSomething()', but given that you know that there's something called
'string' declared in this class (but forget that it wasn't static, or
that this method is static), there's still a risk that you might confuse
the two. Therefore I still think the warning is useful.

0

If this plugin is installed should the external inspection tool still work? when I run it it rips through the code and finds nothing... but if I kick it off in IDEA, it seems fine..

0


I've not used the external tool (hardly anyone does, it seems), but I've been told that it doesn't support third-party plugins.

--Dave

0

that's about what I figured... although I'm a bit surprised it didn't report an error or at least run through the standard set of inspections...

thanks!

0

I just upgraded ipp.jar to 0.7 - the bug was still there so I removed it
completely and ... bug still there. So it's definitely an IG bug, sorry.
Also, is there any way you could check for the presence of IPP and
suppress intentions from IG if it's there? I'm assuming that all the
intentions you've implemented in IG, you've also implemented in IPP. At
the moment I get the same intention ("replace with .equals") twice,
except that one of them works and one of them doesn't ;)

Robbie

0

Hurm. This is very odd. I'll look into it. I may have had problems in both of them, and only fixed one.

I'd love to be able to have IPP test for the presence of IG, and disable the duplicate intentions. Unfortunately, there doesn't seem to be API that would make this possible. Until I figure out a way to do so, you can disable individual intentions via the IPP configuration panel, under IDE Options.

--Dave

0

Dave Griffith wrote:

Unnecessary fully qualified name(*)


(1) Could there be an option not to complain about nested classes being
qualified with their outer class? Some of those class names can't
really be understood without the outer class name as a qualified. I
don't want to write Float instead of Rectangle2D.Float, for example.

(2) I tried to accept the import intention on this example:

package test;

import java.awt.geom.Rectangle2D;

public class TestImport
{
Rectangle2D.Float foo = new Rectangle2D.Float(1, 1, 1, 1);
}


Then I got an exception:

java.lang.NullPointerException
at com.intellij.psi.impl.p.createImportStatement(p.java:249)
at
com.siyeh.ig.verbose.UnnecessaryFullyQualifiedNameInspection.addImportIfNecessary(UnnecessaryFullyQualifiedNameInspection.java:148)
at
com.siyeh.ig.verbose.UnnecessaryFullyQualifiedNameInspection.access$200(UnnecessaryFullyQualifiedNameInspection.java:12)
at
com.siyeh.ig.verbose.UnnecessaryFullyQualifiedNameInspection$UnnecessaryFullyQualifiedNameFix.applyFix(UnnecessaryFullyQualifiedNameInspection.java:67)
at com.intellij.codeInspection.f.n.invoke(n.java:0)
at com.intellij.codeInsight.intention.a.x$8.run(x$8.java:2)
at com.intellij.openapi.application.a.b.runWriteAction(b.java:7)
at com.intellij.codeInsight.intention.a.x$11.run(x$11.java:2)
at com.intellij.openapi.command.b.a.executeCommand(a.java:88)
at com.intellij.codeInsight.intention.a.x$0.run(x$0.java:0)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.intellij.ide.s.a(s.java:43)
at com.intellij.ide.s.dispatchEvent(s.java:6)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


0

In the following generic class, InspectionGadgets suggests that T could
be an interface.

/*

  • Created on 2003-nov-04 at 14:00:13

*/
package test;

public class TestGenericCouldBeInterface]]>
{
void foo() {}
}

0

public static void fill(final int[] array, final int start, final int
step) {
for (int i = 0, j = start; i < array.length; i++, j += step) {
array+ = j;
}
}


How about an option to disable the nested assignments in for
expressions? IMHO its the only place it's justified doing this.

0

Exception happened while adding by hand a catch to a try/finally block.


Error message: Exception happened in local inspection tool: Error not
rethrown
java.lang.ArrayIndexOutOfBoundsException: 0 at
com.siyeh.ig.errorhandling.ErrorRethrownInspection$ErrorRethrownVisitor.
visitTryStatement(ErrorRethrownInspection.java:48) at
com.intellij.psi.impl.source.a.a.bo.accept(bo.java) at
com.intellij.psi.impl.source.a.s.acceptChildren(s.java:62) at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveEle
mentVisitor.java:1) at
com.intellij.psi.JavaElementVisitor.visitCodeBlock(JavaElementVisitor.ja
va:3) at com.intellij.psi.impl.source.a.a.br.accept(br.java:49) at
com.intellij.psi.impl.source.p.acceptChildren(p.java:54) at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveEle
mentVisitor.java:1) at
com.intellij.psi.JavaElementVisitor.visitMethod(JavaElementVisitor.java:
20) at com.intellij.psi.impl.source.bc.accept(bc.java:67) at
com.siyeh.ig.StatementInspection.checkMethod(StatementInspection.java:55
) at com.intellij.codeInsight.h.a.w.a(w.java:108) at
com.intellij.codeInsight.h.a.bj$1.run(bj$1.java:7) at
com.intellij.openapi.application.a.b.runReadAction(b.java:269) at
com.intellij.codeInsight.h.a.bj.a(bj.java:30) at
com.intellij.codeInsight.h.a.bj.access$100(bj.java:29) at
com.intellij.codeInsight.h.a.bj$0.run(bj$0.java:1) at
com.intellij.progress.c.a(c.java:1) at
com.intellij.codeInsight.h.a.bj.run(bj.java:46)

0

The mentioned intention also highlights calls with string argument instead of only calls with boolean arguments.
This won't be too bad itself but by replacing the call with Boolean.valueOf() - as "intended" you get uncompilable code.

0

FYI in build 977 :

java.lang.NullPointerException

at com.intellij.psi.impl.source.e.e.b(e.java:167)

at com.intellij.psi.impl.source.e.e.a(e.java:103)

at com.intellij.psi.impl.source.b.r.b(r.java:86)

at com.intellij.psi.impl.source.b.bu.delete(bu.java:22)

at
com.siyeh.ig.verbose.UnnecessaryInterfaceModifierInspection$UnnecessaryInterfaceModifersFix.applyFix(UnnecessaryInterfaceModifierInspection.java:124)

at com.intellij.codeInspection.t.n.invoke(n.java:9)

at com.intellij.codeInsight.intention.b.x$8.run(x$8.java:9)

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

at com.intellij.codeInsight.intention.b.x$11.run(x$11.java:2)

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

at com.intellij.codeInsight.intention.b.x$0.run(x$0.java:0)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)

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

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

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

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)


0

Dave,

I don't think you have an inspection to see if a checked exception
listed on the throws of a concrete implementation is actually throw. I
could use this some of the time inside of the editor, but I don't
believe I would have it on all of the time. Has it been requested?

Thanks,
Jon

0


There is a built-in inspection that does that: "Redundant throws clause", under "Declaration redundancy".

--Dave "Don't worry, there's no one on the planet who knows all of the features of this software anymore" Griffith

0

When you say built-in, do you mean built-in to your plugin (0.0.6.1) or
built-in to IDEA (977)? I didn't find it in either place...we're talking
about the IDE Settings>Errors, no? Maybe I'm looking right at it and
can't see for looking. The Errors panel now practically needs find
functionality.

Jon

Dave Griffith wrote:

There is a built-in inspection that does that: "Redundant throws clause", under "Declaration redundancy".

--Dave "Don't worry, there's no one on the planet who knows all of the features of this software anymore" Griffith


0

Please sign in to leave a comment.