#141 NullPointerException in Unused... checks

release_3.2
closed
Rick Giles
5
2012-10-10
2003-08-12
Ulrich Obst
No

The UnusedParameter and UnusedLocalVariable check throw
a NullPointerException when applied to sources in the
default package (without package statement)
Maybe other checks are also concerned, but I tried only
those two.

Discussion

  • Rick Giles
    Rick Giles
    2003-08-13

    Logged In: YES
    user_id=539926

    I am unable to create a example that throws a NPE. Can you
    provide a small example?

     
  • Ulrich Obst
    Ulrich Obst
    2003-08-15

    Logged In: YES
    user_id=797552

    Hi,

    This is what I'v done:
    I checked out the CVS version from 2003-08-12 22:15.
    I built the distrivution with the gump ant target.
    The java file called "T0.java" is:

    class T0 {
    public void foo(int n) {
    }
    }

    The config file is attached.
    Here is the session:

    > java -jar dist/checkstyle-3.2/checkstyle-all-3.2.jar -c
    c.xml T0.java
    Starting audit...
    T0.java:0: Got an exception - java.lang.NullPointerException
    Audit done.

    > java -version
    java version "1.4.2"
    Java(TM) 2 Runtime Environment, Standard Edition (build
    1.4.2-b28)
    Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

    > uname -a
    Linux linux 2.4.19-4GB #1 Fri Sep 13 13:19:15 UTC 2002 i686
    unknown

    Hope this helps to reproduce the NPE.
    ulli

     
  • Ulrich Obst
    Ulrich Obst
    2003-08-15

    Checkstyle Config file

     
    Attachments
  • Rick Giles
    Rick Giles
    2003-08-15

    Logged In: YES
    user_id=539926

    Hmm, I get the expected result:

    java -jar checkstyle-all-3.2.jar -c e:\c.xml e:\T0.java
    Starting audit...
    e:\T0.java:2:25: Unused parameter 'n'.
    Audit done.

    There may be a conflict with code in a CLASSPATH file. Is
    the CLASSPATH empty? If not, is there the same behaviour
    when you "clear" CLASSPATH?

    What version of Java, and what OS are you running?

    /Rick

     
  • Rick Giles
    Rick Giles
    2003-08-15

    Logged In: YES
    user_id=539926

    Oops, I didn't notice your java -version and uname -a output.

    Do let us know if it is a CLASSPATH issue.

    /Rick

     
  • Ulrich Obst
    Ulrich Obst
    2003-08-15

    Logged In: YES
    user_id=797552

    OK, here some more information:

    1. CLASSPATH is not set => No classpath issue
    2. Pushed jar file and everything to windows: Same result
      (NPE) => no OS issue
    3. updated sources from cvs, rebuild everything: Same result.
    4. Hacked a err.printStackTrace in the general exception
      handler in TreeWalker.java. Here is the result:

    java.lang.NullPointerException
    at java.util.Hashtable.get(Hashtable.java:333)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.SymbolTable.getPackage(SymbolTable.java:162)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.TableMaker.processImplicitPackage(TableMaker.java:412)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.TableMaker.walkTree(TableMaker.java:244)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.TableMaker.walkSiblings(TableMaker.java:373)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.TableMaker.walkTree(TableMaker.java:205)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.TableMaker.createDefinitions(TableMaker.java:106)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.TableMaker.getTable(TableMaker.java:89)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.ASTManager.buildTree(ASTManager.java:98)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.ASTManager.getCheckNodes(ASTManager.java:153)
    at
    com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck.finishTree(AbstractUsageCheck.java:112)
    at
    com.puppycrawl.tools.checkstyle.TreeWalker.notifyEnd(TreeWalker.java:384)
    at
    com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:356)
    at
    com.puppycrawl.tools.checkstyle.TreeWalker.process(TreeWalker.java:215)
    at
    com.puppycrawl.tools.checkstyle.TreeWalker.process(TreeWalker.java:502)
    at
    com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:266)
    at
    com.puppycrawl.tools.checkstyle.Main.main(Main.java:126)
    Starting audit...
    T0.java:0: Got an exception - java.lang.NullPointerException
    Audit done.

    ulli

     
  • Rick Giles
    Rick Giles
    2003-08-16

    Logged In: YES
    user_id=539926

    Thank you for all your help in identifying the bug. A
    correction has been committed to the 3.2 CVS.

     
  • Oliver Burn
    Oliver Burn
    2003-08-16

    Logged In: YES
    user_id=218824

    Rick, can we close this now?