jplag / JPlag

State-of-the-Art Software Plagiarism & Collusion Detection
https://jplag.github.io/JPlag/
GNU General Public License v3.0
992 stars 290 forks source link

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds - version 5.0.0 #1720

Closed traue closed 1 month ago

traue commented 2 months ago

Hi,

I'm getting the fowling issue on terminal:

Command:

$ java -jar jplag.jar -l java atvs  

Shows:

Loading Submissions   100% [===================================================] 21/21 (0:00:00 / 0:00:00) 
Parsing Submissions     0% [                                                         ]  0/21 (0:00:00 / ?) 
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 42
    at jdk.compiler/com.sun.tools.javac.util.Position$LineTabMapImpl.getColumnNumber(Position.java:266)
    at jdk.compiler/com.sun.tools.javac.util.Position$LineMapImpl.getColumnNumber(Position.java:236)
    at jdk.compiler/com.sun.tools.javac.util.Position$LineTabMapImpl.getColumnNumber(Position.java:253)
    at de.jplag.java.TokenGeneratingTreeScanner.addToken(TokenGeneratingTreeScanner.java:97)
    at de.jplag.java.TokenGeneratingTreeScanner.visitClass(TokenGeneratingTreeScanner.java:165)
    at de.jplag.java.TokenGeneratingTreeScanner.visitClass(TokenGeneratingTreeScanner.java:58)
    at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:855)
    at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:92)
    at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)
    at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)
    at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:152)
    at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:623)
    at de.jplag.java.JavacAdapter.parseFiles(JavacAdapter.java:52)
    at de.jplag.java.Parser.parse(Parser.java:24)
    at de.jplag.java.JavaLanguage.parse(JavaLanguage.java:48)
    at de.jplag.Submission.parse(Submission.java:255)
    at de.jplag.SubmissionSet.parseSubmissions(SubmissionSet.java:159)
    at de.jplag.SubmissionSet.parseAllSubmissions(SubmissionSet.java:111)
    at de.jplag.SubmissionSet.<init>(SubmissionSet.java:49)
    at de.jplag.SubmissionSetBuilder.buildSubmissionSet(SubmissionSetBuilder.java:102)
    at de.jplag.JPlag.run(JPlag.java:73)
    at de.jplag.cli.CLI.runJPlag(CLI.java:132)
    at de.jplag.cli.CLI.main(CLI.java:90)

I'm using JDK 21

Any ideas?

Best regart

T.

tsaglam commented 2 months ago

Interesting, @traue could you provide input files that allow us to reproduce this bug?

traue commented 2 months ago

Hi @tsaglam, thanks for your reply!

I'm using jPlag 5.0.0 and Java 21

$ java -version
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment Homebrew (build 21.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.2, mixed mode, sharing)

I thought it was a folder naming issue, but I renamed each one and the same exception was shown

Attached are the files I am using.

subs.zip

Best regards

T.

SirYwell commented 2 months ago

It looks like some submissions aren't valid Java code (i.e. cut off at the beginning). Javac does error recovery but then emits AST nodes with no proper source position.

I guess JPlag should fail more gracefully here, but I also assume that the submissions aren't supposed to be like that.

tsaglam commented 2 months ago

@SirYwell you are right, the code does not compile. @traue in most cases (also depending on the language), JPlag cannot deal with invalid code. However, the error messages returned by JPlag are not helpful. For that, we can provide a fix. However, regarding invalid code, it is best to filter it out beforehand.

github-actions[bot] commented 1 month ago

Closed by #1768.