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

NullPointerException with cpp2 after va_arg #1586

Open
mpivet-p opened this issue Feb 21, 2024 · 1 comment
Open

NullPointerException with cpp2 after va_arg #1586

mpivet-p opened this issue Feb 21, 2024 · 1 comment
Assignees
Labels
bug Issue/PR that involves a bug language PR / Issue deals (partly) with new and/or existing languages for JPlag minor Minor issue/feature/contribution/change

Comments

@mpivet-p
Copy link

I have the following error when running JPlag on a C file using the cpp2 language parameter:

$> java -jar ~/Downloads/jplag-4.3.0-jar-with-dependencies.jar -l cpp2 check
2024-02-21-06:24:37_092 [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-02-21-06:24:37_102 [main] [INFO] ParallelComparisonStrategy - Start comparing...
line 3:27 no viable alternative at input 'va_arg(arg,unsignedint)'
line 3:30 mismatched input ''c'' expecting {'decltype', 'operator', '(', '*', '&', '~', AndAnd, '::', '...', Identifier}
line 3:33 extraneous input ')' expecting ';'
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "next.children" is null
	at de.jplag.cpp2.CPPTokenListener.getDescendant(CPPTokenListener.java:375)
	at de.jplag.cpp2.CPPTokenListener.enterSimpleDeclaration(CPPTokenListener.java:326)
	at de.jplag.cpp2.grammar.CPP14Parser$SimpleDeclarationContext.enterRule(CPP14Parser.java:5639)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.enterRule(ParseTreeWalker.java:50)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:33)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
	at de.jplag.cpp2.CPPParserAdapter.scan(CPPParserAdapter.java:46)
	at de.jplag.cpp2.CPPLanguage.parse(CPPLanguage.java:48)
	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)

Running it with cpp1 works just fine and doesn't throw any error.

I am running JPlag on a macbook pro m2 with the following version:

$> 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)

These C files are triggering the same error:
1)

void a()
{
	f(va_arg(arg, unsigned int), c, 'c');
}
void a(void)
{
	f(va_arg(arg, unsigned int), "c");
}

But this one works without any issue:

void a(void)
{
	f(va_arg(arg, char), c);
}
@tsaglam tsaglam added bug Issue/PR that involves a bug minor Minor issue/feature/contribution/change language PR / Issue deals (partly) with new and/or existing languages for JPlag labels Feb 21, 2024
@TwoOfTwelve
Copy link
Contributor

This is a case that probably will never be supported by JPlag.
As far as I can tell va_arg is a macro. Macros are't supported by JPlag, as the ANTLR grammar has no support for them. In general you could get around that by evaluating macros first, then calling JPlag. In this specific case, I think the result of the macro is still a special case that doesn't fit the grammar.
If you know a way to support this case in the grammar, feel free to open a PR or an issue in the ANTLR repository.

The cases that are working are doing so only by chance, the resulting AST is still incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue/PR that involves a bug language PR / Issue deals (partly) with new and/or existing languages for JPlag minor Minor issue/feature/contribution/change
Projects
None yet
Development

No branches or pull requests

3 participants