Menu

#359 pmd parse error (but only in case of pmd warnings)

closed
pmd (543)
5
2012-10-07
2005-08-30
No

I have created a small test set of JDK 5 test code, if I
run PMD on it, I get the following.

 [java] Buildfile: D:\CQM\inst\jmodules\sandbox5

\build.xml
[java] pmd-init:
[java] pmd:
[java] [pmd] No problems found!
[java] BUILD SUCCESSFUL
[java] Total time: 3 seconds

I have now added some unused variables to some files
in the test-set ( see CVS diff below )

cvs -z9 -q diff GenericStringArrayListToo.java
GenericStringArrayList.java (in directory
D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode)
Index: GenericStringArrayListToo.java
=========================================
==========================
RCS file: /data/cvs/I-
Metricstool/swdeqa/jmodules/sandbox5/src/de/spm/swd
eqa/sandbox/tigercode/GenericStringArrayListToo.java,v
retrieving revision 1.1
diff -r1.1 GenericStringArrayListToo.java
26a27

int notUsed;

Index: GenericStringArrayList.java

==========================
RCS file: /data/cvs/I-
Metricstool/swdeqa/jmodules/sandbox5/src/de/spm/swd
eqa/sandbox/tigercode/GenericStringArrayList.java,v
retrieving revision 1.4
diff -r1.4 GenericStringArrayList.java
26a27
int notUsed;

*CVS exited normally with code 1***

javac compiles without problems

Buildfile: .\build.xml
init:
[echo] javac.source: 1.5
[echo] javac.target: 1.5
compile:
[echo] compile-classpath=
[javac] Compiling 2 source files to
D:\CQM\inst\jmodules\sandbox5\build
BUILD SUCCESSFUL

If I now run PMD I get the following

 [java] Buildfile: D:\CQM\inst\jmodules\sandbox5

\build.xml
[java] pmd-init:
[java] pmd:
[java] [pmd]
[java] [pmd] D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\GenericStringArr
ayList.java 27 Avoid unused local variables such
as 'notUsed'
[java] [pmd] D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\GenericStringArr
ayListToo.java 27 Avoid unused local variables
such as 'notUsed'
[java] [pmd] D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\EnhancedForLoo
p.java

    -       Error while parsing

D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\EnhancedForLoo
p.java
[java] [pmd] D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\EnumType.java
- Error while parsing
D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\EnumType.java
[java] [pmd] D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\StaticImport.java

    -       Error while parsing

D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercodeStaticImport.java
[java] [pmd] D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
- Error while parsing
D:\CQM\inst\jmodules\sandbox5
\src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
[java] BUILD SUCCESSFUL
[java] Total time: 3 seconds

I see this with PMD 3.2 , I also see the problem with the
JDK5 production code that we have,
it seems to be a general problem?

If you're interested, I can send you the test-set that we
have.

Discussion

  • Tom Copeland

    Tom Copeland - 2005-08-30

    Logged In: YES
    user_id=5159

    Hi Pieter -

    Hm. Could you try this jar? It's got some bug fixes that
    have happened since the 3.2 release:

    http://infoether.com/~tom/pmd-3.2.jar

    Thanks,

    tom

     
  • Tom Copeland

    Tom Copeland - 2005-08-31

    Logged In: YES
    user_id=5159

    Or if you prefer, you can send me your test files and I'll
    give them a whirl....

    Yours,

    tom

     
  • pbloemendaal

    pbloemendaal - 2005-09-01

    Logged In: YES
    user_id=194131

    ok, short recap, with the original pmd 3.2 jar I got the thing
    below, after I added some unused vars, I on purpose provoked
    some pmd warnings

     [java] Buildfile: D:\CQM\inst\jmodules\sandbox5\build.xml
     [java] pmd-init:
     [java] pmd:
     [java]       [pmd]
     [java]       [pmd] D:\CQM\inst\jmodules\sandbox5
    

    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    t.java 27 Avoid unused local variables such as 'notUsed'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    t.java 49 Avoid unused local variables such as 'newIter'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    tToo.java 27 Avoid unused local variables such
    as 'notUsed'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    tToo.java 49 Avoid unused local variables such
    as 'newIter'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\EnhancedForLoop.jav
    a

        -       Error while parsing
    

    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\EnhancedForLoop.jav
    a
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\EnumType.java
    - Error while parsing
    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\EnumType.java
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\StaticImport.java
    - Error while parsing
    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\StaticImport.java
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
    - Error while parsing
    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
    [java] BUILD SUCCESSFUL
    [java] Total time: 4 seconds

    after I put in place the patched pmd 3.2 jar that you provided I
    get

     [java] Buildfile: D:\CQM\inst\jmodules\sandbox5\build.xml
     [java] pmd-init:
     [java] pmd:
     [java] BUILD FAILED
     [java] D:\CQM\inst\jmodules\sandbox5\build.xml:241:
    

    java.lang.IllegalArgumentException: Unable to find rule
    ExplicitCallToFinalize; perhaps the rule name is mispelled?
    [java] Total time: 2 seconds
    [java] Java Result: 1

    after I have removed ExplicitCallToFinalize from the ruleset I
    get

     [java] Buildfile: D:\CQM\inst\jmodules\sandbox5\build.xml
     [java] pmd-init:
     [java] pmd:
     [java] BUILD FAILED
     [java] D:\CQM\inst\jmodules\sandbox5\build.xml:241:
    

    java.lang.IllegalArgumentException: Unable to find rule
    ExceptionTypeChecking; perhaps the rule name is mispelled?
    [java] Total time: 2 seconds
    [java] Java Result: 1

    after I have removed ExceptionTypeChecking from the ruleset
    I get

     [java] Buildfile: D:\CQM\inst\jmodules\sandbox5\build.xml
    
     [java] pmd-init:
    
     [java] pmd:
     [java]       [pmd]
     [java]       [pmd] D:\CQM\inst\jmodules\sandbox5
    

    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    t.java 27 Avoid unused local variables such as 'notUsed'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    t.java 49 Avoid unused local variables such as 'newIter'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    tToo.java 27 Avoid unused local variables such
    as 'notUsed'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    tToo.java 49 Avoid unused local variables such
    as 'newIter'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\EnhancedForLoop.jav
    a

        -       Error while parsing
    

    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\EnhancedForLoop.jav
    a
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\EnumType.java
    - Error while parsing
    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\EnumType.java
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\StaticImport.java
    - Error while parsing
    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\StaticImport.java
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
    - Error while parsing
    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
    [java] BUILD SUCCESSFUL
    [java] Total time: 4 seconds

    conclusion: the problem is not solved by the patch, I'm
    sorry ...

    the 3 file testset, "int notUsed;" disabled, original pmd 3.2 jar
    gives

     [java] Buildfile: D:\CQM\inst\jmodules\sandbox5\build.xml
     [java] pmd-init:
     [java] pmd:
     [java]       [pmd] No problems found!
     [java] BUILD SUCCESSFUL
     [java] Total time: 3 seconds
    

    the 3 file testset, "int notUsed;" enabled, original pmd 3.2 jar
    gives

    wrap-target:
    [java] Buildfile: D:\CQM\inst\jmodules\sandbox5\build.xml
    [java] pmd-init:
    [java] pmd:
    [java] [pmd]
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    t.java 27 Avoid unused local variables such as 'notUsed'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    tToo.java 27 Avoid unused local variables such
    as 'notUsed'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java

        -       Error while parsing
    

    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
    [java] BUILD SUCCESSFUL
    [java] Total time: 3 seconds

    the 3 file testset, "int notUsed;" enabled, PATCH for pmd 3.2
    jar gives

     [java] Buildfile: D:\CQM\inst\jmodules\sandbox5\build.xml
     [java] pmd-init:
     [java] pmd:
     [java]       [pmd]
     [java]       [pmd] D:\CQM\inst\jmodules\sandbox5
    

    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    t.java 27 Avoid unused local variables such as 'notUsed'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\GenericStringArrayLis
    tToo.java 27 Avoid unused local variables such
    as 'notUsed'
    [java] [pmd] D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java

        -       Error while parsing
    

    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
    [java] BUILD SUCCESSFUL
    [java] Total time: 3 seconds

    the 3 file testset, "int notUsed;" disabled, PATCH for pmd 3.2
    jar gives

     [java] Buildfile: D:\CQM\inst\jmodules\sandbox5\build.xml
     [java] pmd-init:
     [java] pmd:
     [java]       [pmd]
     [java]       [pmd] D:\CQM\inst\jmodules\sandbox5
    

    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java

        -       Error while parsing
    

    D:\CQM\inst\jmodules\sandbox5
    \src\de\spm\swdeqa\sandbox\tigercode\VarArgs.java
    [java] BUILD SUCCESSFUL
    [java] Total time: 3 seconds

    conclusions, seems that the situation has gotton worse
    ( I hope I did not mix up the versions, I'm pretty sure I didn't
    though)

     
  • pbloemendaal

    pbloemendaal - 2005-09-01
     
  • Tom Copeland

    Tom Copeland - 2005-09-01

    Logged In: YES
    user_id=5159

    Hi Pieter -

    Thanks for the code zip file. I'm still having trouble
    reproducing the errors you're see, though... which rulesets
    are you using?

    Also, this is probably a silly question, but since you're
    using the Ant task, are you setting the "targetjdk"
    attribute to "1.5"?

    Thanks,

    tom

     
  • pbloemendaal

    pbloemendaal - 2005-09-02

    Logged In: YES
    user_id=194131

    Hi Tom,
    Sorry for that, no, I did not set the "targetjdk" property.
    I never noticed that such thing exists. We're using PMD for
    quite a while now, the migration to JDK5 seems to go very
    smooth :-). I never bothered to check if a "targetjdk" property
    or so existed. Still funny that if now warnings are there, every
    thing compiles and parses fine, and that if warnings are there,
    we get compile errors?

    Ok,
    1) I attached our rules file
    2) I will give it another try with the "targetjdk" prop :-)
    3) I'll get back to you after the weekend
    4) Maybe you should throw an exception if your parsing jdk5
    code, and the property is not set?

    Pieter

     
  • pbloemendaal

    pbloemendaal - 2005-09-02
     
  • pbloemendaal

    pbloemendaal - 2005-09-02

    Logged In: YES
    user_id=194131

    Hi Tom,

    I'm sorry once more, the targetjdk option solved my problem.
    I had to outcomment some checks, that were not found.

    • Unable to find rule ExplicitCallToFinalize; perhaps the rule
      name is mispelled?
    • Unable to find rule AvoidThrowingCertainExceptionTypes;
      perhaps the rule name is mispelled?
    • Unable to find rule ExceptionTypeChecking; perhaps the
      rule name is mispelled?

    I'll check the docs on them.

    Still funny that if no warnings are there, every
    thing compiles and parses fine, and that if warnings are there,
    we get compile errors? Maybe you should throw an exception
    if your parsing jdk5 code, and the property is not set?

    Have a nice weekend.
    Pieter

     
  • Tom Copeland

    Tom Copeland - 2005-09-02

    Logged In: YES
    user_id=5159

    the targetjdk option solved my problem

    Cool, glad to hear it, also, all the Ant task options are
    listed here:
    http://pmd.sourceforge.net/ant-task.html

    I had to outcomment some checks

    Hm, yes, here's the deal with each of those:

    • ExplicitCallToFinalize was in two rulesets (design and
      finalize) so I removed it from finalize
    • ExceptionTypeChecking was redundant since there's already
      a AvoidInstanceofChecksInCatchClause rule in the design
      ruleset, so I deleted it
    • AvoidThrowingCertainExceptionTypes was split into two
      rules (AvoidThrowingRawExceptionTypes and
      AvoidThrowingNullPointerException) in the 3.2 release

    Maybe you should throw an exception
    if your parsing jdk5 code, and the property is not set?

    Yup, it's supposed to do that... I think these warnings will
    show up if you run Ant with the verbose option - e.g., "ant
    -v pmd". Can you try that and see if it shows a better
    error message?

    Yours,

    Tom

     
  • pbloemendaal

    pbloemendaal - 2005-09-02

    Logged In: YES
    user_id=194131

    allmost correct, this

    • ExplicitCallToFinalize was in two rulesets (design and
      finalize) so I removed it from finalize

    should say

    • ExplicitCallToFinalize is still in finalizers.xml, but it was
      renamed into AvoidCallingFinalize

    thanks, case closed

    pieter

     
  • Tom Copeland

    Tom Copeland - 2005-09-02

    Logged In: YES
    user_id=5159

    Oh gosh, you're right Pieter, thanks. I've got two
    changelog entries on that, I'll clean them up. Thanks!

    Yours,

    Tom

     

Log in to post a comment.

MongoDB Logo MongoDB