[ pmd-Bugs-1947823 ] Java CPD - java.lang.IndexOutOfBoundsException

View: New views
1 Messages — Rating Filter:   Alert me  

[ pmd-Bugs-1947823 ] Java CPD - java.lang.IndexOutOfBoundsException

by SourceForge.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bugs item #1947823, was opened at 2008-04-21 15:21
Message generated for change (Comment added) made by rpelisse
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=479921&aid=1947823&group_id=56262

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: cpd
Group: None
>Status: Closed
Resolution: None
Priority: 5
Private: No
Submitted By: Martin Brownlie (martinbrownlie)
Assigned to: Ryan Gustafson (rgustav)
Summary: Java CPD - java.lang.IndexOutOfBoundsException

Initial Comment:
Version of PMD - 4.2.1

If I add a JSP file to CPD that cannot be parsed it throws a TokenMgrError.

If i then create a new CPD class and
add a valid JSP file and call cpd.go() it always throws a java.lang.IndexOutOfBoundsException exception.

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 884, Size: 689
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at net.sourceforge.pmd.cpd.MatchAlgorithm.tokenAt(MatchAlgorithm.java:50)
at net.sourceforge.pmd.cpd.MatchAlgorithm.hash(MatchAlgorithm.java:96)
at net.sourceforge.pmd.cpd.MatchAlgorithm.findMatches(MatchAlgorithm.java:59)
at net.sourceforge.pmd.cpd.CPD.go(CPD.java:51)
at debug.Test.main(Test.java:35)

Originally asked as a question ->
http://sourceforge.net/forum/forum.php?thread_id=2011384&forum_id=188192

I've attatched a small test to replicate this, wrapped
in a maven2 project.


----------------------------------------------------------------------

>Comment By: Romain PELISSE (rpelisse)
Date: 2009-08-16 16:26

Message:
This bug entry eems closed to me.

----------------------------------------------------------------------

Comment By: Martin Brownlie (martinbrownlie)
Date: 2008-05-01 15:55

Message:
Logged In: YES
user_id=1707718
Originator: YES

Apologies, I've only had a chance to go back to this today.

You're absolutely right. There's nothing wrong with the workaround.

It was my rubbish code and environmental issues.

Thanks again.

----------------------------------------------------------------------

Comment By: Ryan Gustafson (rgustav)
Date: 2008-04-23 01:37

Message:
Logged In: YES
user_id=342470
Originator: NO

Hmm, works for me, only the parseError test fails.

----------------------------------------------------------------------

Comment By: Martin Brownlie (martinbrownlie)
Date: 2008-04-22 11:07

Message:
Logged In: YES
user_id=1707718
Originator: YES

Thanks for the update.

I think i've oversimplified the test case.  The workround is good when
you're only
processing JSP's but doesn't work when you need to,in my case, process
Java and Jsp files at the same time.


I've updated the test case to illustrate.
File Added: PMD-Error.zip

----------------------------------------------------------------------

Comment By: Ryan Gustafson (rgustav)
Date: 2008-04-21 20:57

Message:
Logged In: YES
user_id=342470
Originator: NO

Thank you for the test case, this helps immensely!

The problem has to do with how the token ids are assigned when processing
multiple files, and the fact those ids are also used as index into the list
of tokens maintain in the CPD instance.  The id counter is static, but the
list is linked to the CPD instance.  Your 2nd CPD instance is causing
things to break.  In fact, you'll find that if you just create a new CPD
instance between 2 valid files (do not call CPD.go() between them), you can
duplicate the same error.

You can work around this for now in two ways:
1) Don't create a new CPD instance just because of a bogus file, just keep
adding files.
2) If you must create a new CPD instance, call TokenEntry.clearImages()
before adding any files to it.  Creating a new CPD instance will _toss_out_
all the files parsed so far, meaning when CPD.go(), not every file will be
included in the detection (you may get false negatives).

Unless you can demonstrate a real need to have this fixed on the 4.2.x
branch, I'll see about fixing it for PMD 5.0.  I need to either (a) clear
the static cache whenever a new CPD is constructed, or (b) stop using
static stuff in CPD.  I prefer (b), which is more work than (a).

While I'm at it, we need a new PMD rule about use of static mutable
objects in code not annotated with @ThreadSafe.  Such fugly code would be
caught by said rule.  Maybe there's other such crud in the PMD code base
that should be cleaned up.


----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=479921&aid=1947823&group_id=56262

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Pmd-devel mailing list
Pmd-devel@...
https://lists.sourceforge.net/lists/listinfo/pmd-devel