Several Bugs found (Testcases included)
A source code analyzer
Brought to you by:
adangel,
juansotuyo
There are several bugs in this test pack.
1) Null source file name not caught.
2) Prefixed unary operators on this scoped attributes
causes null pointer exception in optimization rules.
3) Local variable could be final reports incorrect
results on a unarz incremented expression.
4) In design rules throwing a runtime exception causes
a classCastException when determining stack trace
preservation.
5) Annotation on local var causes parse exceptions.
6) Annotation on enum constants causes parse exceptions.
JUnit test cases are attached.
Logged In: YES
user_id=5159
Assigning to "no one" just so any of the other fellows can
work on this and not feel like they're stepping on my toes
or something...
Yours,
Tom
Logged In: YES
user_id=1373398
I think I've fixed some of the parsing problems when I ran
pmd on the jdk 1.5 and 1.6 source code. That was integrated
after 3.8 was released. I'm looking at the test suite now to
see if that's the case.
Xavier
Logged In: YES
user_id=1373398
With the current cvs version, only the null file name and
the local variable could be final prefixed unary problems fail.
Xavier
Logged In: YES
user_id=1373398
I've fixed the false + in LocalVariableCouldBeFinal so the
only problem left is the null source file name.
I don't fully understand what the problem is there as the
error occurs outside PMD when the Reader object is created
once the line:
if (insSourceFile == null) throw new
NullPointerException("insSourceFile == null");
is commented out in your TestPMD class.
Could you please describe the problem in more details?
Thanks,
Xavier
Logged In: YES
user_id=886572
Simply that PMD should throw a NullPointerException if a
null sourcefile name is passed to it.
-- Robert
Logged In: YES
user_id=1373398
Originator: NO
I still don't get it but first, I've uploaded a newer version of pmd-3.8.jar that contains the recent changes since the 3.8 release. If you use that version, you can validate that all other problems are fixed. It's available at:
http://brittanysoftware.com/pmd/pmd-3.8.jar
Now, concerning the null source file issue:
In your test case, the file "test-files/Main.java" does not exist.
If I uncomment your code "if (insSourceFile == null)" in executePMDOnFile(), there is an NPE thrown in your code when creating the reader:
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at com.solidw.pmd.test.TestPMD.executePMDOnFile(Unknown Source)
at com.solidw.pmd.test.TestPMD.testNullSourceFilename(Unknown Source)
If the file exists but context.setSourceCodeFilename is not called in the test case prior to calling executePMDOnFile as from the comment that seems to be the original problem, the code still works fine and no exception is thrown.
As there were a number of bugs reported here and all the others are fixed, I would suggest that if you feel the problem is indeed in PMD, you should open a new bug report detailing the problem.
Please provide the exception trace that you get and the reason why you feel the current behavior is not appropriate.
Thanks,
Xavier