jsonschema2pojo
jsonschema2pojo copied to clipboard
NullPointerException from Maven plugin when sourceDirectory is ../src/json
Trying to use this as part of a maven module and I want to do
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<sourceDirectory>${parent.basedir}/src/json</sourceDirectory>
...
but doing so causes an issue:
Execution default of goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.0.1:generate failed: Unrecognised URI, can't resolve this: file:/home/me/projects/foo-schema/foo-schema-java/$%7Bparent.basedir%7D/src/json: /home/me/projects/foo-schema/foo-schema-java/${parent.basedir}/src/json
it seems that relative paths also cause an issue
doing
<sourceDirectory>../src/json</sourceDirectory>
throws
Execution default of goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.0.1:generate failed.: NullPointerException -> [Help 1]
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
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:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.0.1:generate failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
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:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.NullPointerException
at java.io.File.<init> (File.java:277)
at org.jsonschema2pojo.util.URLUtil.parseURL (URLUtil.java:38)
at org.jsonschema2pojo.maven.Jsonschema2PojoMojo.execute (Jsonschema2PojoMojo.java:789)
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:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Did you mean ${project.basedir}
?
No, I meant I want to use it as a module and the parent has the source json. But your comment got me thinking that I was using old style mvn 2 tag. The right way is ${project.parent.basedir}
and that works, so thanks!
The relative path is still an issue, though.
Here's the line of code:
https://github.com/joelittlejohn/jsonschema2pojo/blob/jsonschema2pojo-1.0.1/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java#L789
I think the only way this could happen is if the sourceDirectory was null, but I'm not sure. Are you certain the pom.xml was in state you think it was when you received this error?
Feel free to submit a PR for this if you can track it down.
hey @joelittlejohn sorry for the delay. Not sure I follow you, My structure is
myproject
├── myproject-java
│ ├── pom.xml
├── pom.xml
├── src
│ └── json
│ └── file.json
so from module myproject-java's pom doing ${project.parent.basedir}/src/json
works but ../src/json
throws the NPE
perhaps FilenameUtils.normalize is doing something weird?
I'm seeing the same issue. Using ${project.basedir}/src/main/resources/schema, ${basedir}/src/main/resources/schema or src/main/resources/schema
I can confirm this issue. FilenameUtils.normalize(String)
returns null
in case the argument contains ../
without a leading directory, so a NullPointerException is thrown if the <sourceDirectory>
of the Maven plugin contains something like ../schemas
.
Unfortunately I'm also in the position where the schema files are located outside of the project directory. Is there any chance that the usage of FilenameUtils.normalize(String)
can be replaced by an alternative that respects ../
?
@remcox As a workaround, if you can use something like ${project.parent.basedir}/../schemas
then this should work.
To fix this, I suspect we can use Paths.get(sourceDirectory).normalize().toString()
instead of FilenameUtils.
Maven does not expand ${project.parent.basedir}
in my case; I'm not sure why as the pom does have a parent. But I'm now using something like:
<sourceDirectory>${project.basedir}/../../schemas</sourceDirectory>
and this works fine. Thanks!