Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python parser crashes JPlag #1481

Closed
reijne opened this issue Jan 16, 2024 · 1 comment
Closed

Python parser crashes JPlag #1481

reijne opened this issue Jan 16, 2024 · 1 comment
Labels
language PR / Issue deals (partly) with new and/or existing languages for JPlag question A question, so neither a bug nor a enhancement proposal.

Comments

@reijne
Copy link

reijne commented Jan 16, 2024

A python file containing only whitespace crashes JPlag.

Using the jar with dependencies supplied in the latest release at this time: 4.3.0

Command:
java -jar jplag-4.3.0-jar-with-dependencies.jar -l python3 -t 2 python_files

Java version:
java version "17.0.9" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)

Contents of python files: Two duplicate submissions of a single python file, which only contains a space character.
whitespace.py

 

Output:

java -jar jplag-4.3.0-jar-with-dependencies.jar -l python3 -t 2 python_files
2024-01-16-04:01:55_636 [main] [INFO] LanguageLoader - Available languages: '[C/C++ Scanner [basic markup], C/C++ Parser, C# 6 Parser, EMF metamodel, Go Parser, Javac based AST plugin, Kotlin Parser, Python3 Parser, R Parser, Rust Language Module, Scala parser, SchemeR4RS Parser [basic markup], Swift Parser, Text Parser (naive)]'
2024-01-16-04:01:55_647 [main] [INFO] ParallelComparisonStrategy - Start comparing...
line 1:1 extraneous input ' ' expecting {<EOF>, STRING, NUMBER, 'def', 'return', 'raise', 'from', 'import', 'global', 'nonlocal', 'assert', 'if', 'while', 'for', 'try', 'with', 'lambda', 'not', 'None', 'True', 'False', 'class', 'yield', 'del', 'pass', 'continue', 'break', 'async', 'await', NEWLINE, NAME, '...', '*', '(', '[', '+', '-', '~', '{', '@'}
line 1:1 extraneous input ' ' expecting {<EOF>, STRING, NUMBER, 'def', 'return', 'raise', 'from', 'import', 'global', 'nonlocal', 'assert', 'if', 'while', 'for', 'try', 'with', 'lambda', 'not', 'None', 'True', 'False', 'class', 'yield', 'del', 'pass', 'continue', 'break', 'async', 'await', NEWLINE, NAME, '...', '*', '(', '[', '+', '-', '~', '{', '@'}
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: offset -4, count 5, length 4096
	at java.base/java.lang.String.checkBoundsOffCount(String.java:4593)
	at java.base/java.lang.String.<init>(String.java:523)
	at org.antlr.v4.runtime.CodePointCharStream$CodePoint8BitCharStream.getText(CodePointCharStream.java:160)
	at org.antlr.v4.runtime.CommonToken.getText(CommonToken.java:170)
	at org.antlr.v4.runtime.tree.TerminalNodeImpl.getText(TerminalNodeImpl.java:54)
	at de.jplag.python3.JplagPython3Listener.visitTerminal(JplagPython3Listener.java:210)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:29)
	at de.jplag.python3.Parser.parseFile(Parser.java:62)
	at de.jplag.python3.Parser.parse(Parser.java:39)
	at de.jplag.python3.Language.parse(Language.java:45)
	at de.jplag.Submission.parse(Submission.java:249)
	at de.jplag.SubmissionSet.parseSubmissions(SubmissionSet.java:147)
	at de.jplag.SubmissionSet.parseAllSubmissions(SubmissionSet.java:103)
	at de.jplag.SubmissionSet.<init>(SubmissionSet.java:45)
	at de.jplag.SubmissionSetBuilder.buildSubmissionSet(SubmissionSetBuilder.java:78)
	at de.jplag.JPlag.run(JPlag.java:55)
	at de.jplag.cli.CLI.main(CLI.java:91)

When running the command listed above, I would not expect an uncaught top level exception. This behavior causes checks for other files in the submission to be disregarded, as the program crashes.

@tsaglam tsaglam added the question A question, so neither a bug nor a enhancement proposal. label Jan 25, 2024
@tsaglam tsaglam added the language PR / Issue deals (partly) with new and/or existing languages for JPlag label Feb 6, 2024
@TwoOfTwelve
Copy link
Contributor

In the current version of JPlag ANTLR does not throw an exception for this, so the error should not occur anymore. However, there won't be a general fix for this, because then submission that cause ANTLR to crash would not be shown in the final result and the error message might easily be missed in the log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language PR / Issue deals (partly) with new and/or existing languages for JPlag question A question, so neither a bug nor a enhancement proposal.
Projects
None yet
Development

No branches or pull requests

3 participants