antlr / antlr4test-maven-plugin

A maven plugin used to test the grammars-v4 repo grammars
BSD 3-Clause "New" or "Revised" License
17 stars 16 forks source link

NullPointerException under certain conditions when using new Scenario configuration #21

Closed gilcesarf closed 4 years ago

gilcesarf commented 4 years ago

Using the new scenario configuration, I have found a NPE only when using the verbose=true option. Digging into the code, I have found that baseDir does not get its default value if using the new Scenario configuration, as shown in log messages. Two possible workarounds: first, to setup manually the baseDir with . within the scenario; or second, to disable verbose option.

The problematic Scenario configuration:

<scenario>
    <scenarioName>Basic</scenarioName>
    <enabled>true</enabled>
    <verbose>false</verbose>
    <showTree>true</showTree>
    <entryPoint>query</entryPoint>
    <grammarName>MySQL</grammarName>
    <packageName>io.trustep.grammars.mysql</packageName>
    <caseInsensitiveType>None</caseInsensitiveType>
    <exampleFiles>src/test/antlr4/io/trustep/grammars/mysql/basic</exampleFiles>
    <fileEncoding>ISO-8859-1</fileEncoding>
    <testFileExtension>sql</testFileExtension>
</scenario>

The logged error:

Evaluating Scenario: Basic
baseDir: null
exampleFiles: src/test/antlr4/io/trustep/grammars/mysql/basic
java.lang.NullPointerException
    at com.khubla.antlr.antlr4test.GrammarTestMojo.testScenarios(GrammarTestMojo.java:284)
    at com.khubla.antlr.antlr4test.GrammarTestMojo.execute(GrammarTestMojo.java:169)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
gilcesarf commented 4 years ago

I am fixing this issue by checking the default values of scenario before start execution, and injecting the corresponding default values from Mojo if necessary.

gilcesarf commented 4 years ago

Already fixed the issue. Waiting on PR to close issue