mulesoft-labs / raml-for-jax-rs

This project is all about two way transformation of JAX-RS-annotated Java code to RAML API description and back.
Other
295 stars 181 forks source link

NPE when trying to generate from RAML #47

Closed richard-instil closed 9 years ago

richard-instil commented 9 years ago

I have pulled down the latest version of raml-for-jax-rs and installed the maven plugin in my local repo. I wish to generate Java from a RAML file. When I run mvn compile I am getting the following NPE. As far as I know my RAML is perfectly valid, but as a test I swapped it out for the RAML in examples listed under this repo. It produced the same errors. The RAML file is being copied to target/classes/raml. I have included the error message and POM below.

Using RAML files: [/Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/my.raml] [INFO] Generating Java classes from: /Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/my.raml [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.664 s [INFO] Finished at: 2015-03-06T15:00:32+00:00 [INFO] Final Memory: 6M/81M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.raml.plugins:raml-jaxrs-maven-plugin:1.3.3-SNAPSHOT:generate (default) on project test-raml-to-jax-rs: Error generating Java classes from: /Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/my.raml: NullPointerException -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.raml.plugins:raml-jaxrs-maven-plugin:1.3.3-SNAPSHOT:generate (default) on project test-raml-to-jax-rs: Error generating Java classes from: /Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/my.raml at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216) at org.apache.maven.cli.MavenCli.main(MavenCli.java:160) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) 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.MojoExecutionException: Error generating Java classes from: /Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/my.raml at org.raml.jaxrs.codegen.maven.RamlJaxrsCodegenMojo.execute(RamlJaxrsCodegenMojo.java:221) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 19 more Caused by: java.lang.NullPointerException at org.raml.parser.rule.SchemaRule.getGlobalSchemaNode(SchemaRule.java:167) at org.raml.parser.rule.SchemaRule.doValidateValue(SchemaRule.java:65) at org.raml.parser.rule.SchemaRule.doValidateValue(SchemaRule.java:48) at org.raml.parser.rule.DefaultTupleRule.validateValue(DefaultTupleRule.java:108) at org.raml.parser.visitor.YamlDocumentValidator.onScalar(YamlDocumentValidator.java:115) at org.raml.parser.visitor.NodeVisitor.visitScalar(NodeVisitor.java:256) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:222) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.visitSequence(NodeVisitor.java:247) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:226) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitDocument(NodeVisitor.java:209) at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:65) at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:95) at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:77) at org.raml.jaxrs.codegen.core.AbstractGenerator.run(AbstractGenerator.java:558) at org.raml.jaxrs.codegen.maven.RamlJaxrsCodegenMojo.execute(RamlJaxrsCodegenMojo.java:218) ... 21 more

My POM:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<groupId>my</groupId>
<artifactId>test-raml-to-jax-rs</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.raml.plugins</groupId>
            <artifactId>raml-jaxrs-maven-plugin</artifactId>
            <version>1.3.3-SNAPSHOT</version>
            <configuration>
                <!-- Use sourcePaths if you want to provide a single RAML file or a list of RAML files -->
                <sourcePaths>
                    <sourcePath>
                    ${basedir}/src/main/resources/raml/my.raml
                    </sourcePath>
                </sourcePaths>
                <sourceDirectory>${basedir}/src/main/resources/raml</sourceDirectory>
                <!-- Optionally configure outputDirectory if you don't like the default value: ${project.build.directory}/generated-sources/raml-JAX-RS -->
                <!-- Replace with your package name -->
                <basePackageName>my</basePackageName>
                <!-- Valid values: 1.1 2.0 -->
                <JAX-RSVersion>2.0</JAX-RSVersion>
                <useJsr303Annotations>true</useJsr303Annotations>
                <!-- Valid values: jackson1 jackson2 gson none -->
                <jsonMapper>jackson2</jsonMapper>
                <removeOldOutput>true</removeOldOutput>
                <!-- Optionally set extensions to a list of fully qualified names of classes
                that implement org.raml.jaxrs.codegen.core.ext.GeneratorExtension -->
                <!-- for example:
                <extensions>
                    <param>com.abc.AuthorizationAnnotationExtension</param>
                    <param>com.abc.ParameterFilterExtension</param>
                </extensions>
                -->
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

petrochenko-pavel-a commented 9 years ago

It looks like an issue in raml parser. From which we depending. Looking.

Regards, Pavel 06 Мар 2015 г. 16:11 пользователь "richard-instil" notifications@github.com написал:

I have pulled down the latest version of raml-for-jax-rs and installed the maven plugin in my local repo. I wish to generate Java from a RAML file. When I run mvn compile I am getting the following NPE. As far as I know my RAML is perfectly valid, but as a test I swapped it out for the RAML in examples listed under this repo. It produced the same errors. The RAML file is being copied to target/classes/raml. I have included the error message and POM below.

Using RAML files: [/Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/bitnet-payment-api.raml] [INFO] Generating Java classes from: /Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/bitnet-payment-api.raml

[INFO]

[INFO] BUILD FAILURE

[INFO]

[INFO] Total time: 2.664 s [INFO] Finished at: 2015-03-06T15:00:32+00:00 [INFO] Final Memory: 6M/81M

[INFO]

[ERROR] Failed to execute goal org.raml.plugins:raml-jaxrs-maven-plugin:1.3.3-SNAPSHOT:generate (default) on project test-raml-to-jax-rs: Error generating Java classes from: /Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/bitnet-payment-api.raml: NullPointerException -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.raml.plugins:raml-jaxrs-maven-plugin:1.3.3-SNAPSHOT:generate (default) on project test-raml-to-jax-rs: Error generating Java classes from: /Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/bitnet-payment-api.raml at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216) at org.apache.maven.cli.MavenCli.main(MavenCli.java:160) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) 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.MojoExecutionException: Error generating Java classes from: /Users/richard/InstilWorkspace/test-raml-to-jax-rs/src/main/resources/raml/bitnet-payment-api.raml at org.raml.jaxrs.codegen.maven.RamlJaxrsCodegenMojo.execute(RamlJaxrsCodegenMojo.java:221) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 19 more Caused by: java.lang.NullPointerException at org.raml.parser.rule.SchemaRule.getGlobalSchemaNode(SchemaRule.java:167) at org.raml.parser.rule.SchemaRule.doValidateValue(SchemaRule.java:65) at org.raml.parser.rule.SchemaRule.doValidateValue(SchemaRule.java:48) at org.raml.parser.rule.DefaultTupleRule.validateValue(DefaultTupleRule.java:108) at org.raml.parser.visitor.YamlDocumentValidator.onScalar(YamlDocumentValidator.java:115) at org.raml.parser.visitor.NodeVisitor.visitScalar(NodeVisitor.java:256) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:222) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.visitSequence(NodeVisitor.java:247) at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:226) at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180) at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151) at org.raml.parser.visitor.NodeVisitor.visitDocument(NodeVisitor.java:209) at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:65) at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:95) at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:77) at org.raml.jaxrs.codegen.core.AbstractGenerator.run(AbstractGenerator.java:558) at org.raml.jaxrs.codegen.maven.RamlJaxrsCodegenMojo.execute(RamlJaxrsCodegenMojo.java:218) ... 21 more

My POM:

<?xml version="1.0" encoding="UTF-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

bitnet.io test-raml-to-jax-rs 1.0-SNAPSHOT org.raml.plugins raml-jaxrs-maven-plugin 1.3.3-SNAPSHOT ${basedir}/src/main/resources/raml/bitnet-payment-api.raml ${basedir}/src/main/resources/raml bitnet.io 2.0 true jackson2 true generate generate-sources

— Reply to this email directly or view it on GitHub https://github.com/mulesoft/raml-for-jax-rs/issues/47.

ddossot commented 9 years ago

In that regard, it's a little scary that raml-for-jax-rs depends on a snapshot build of the RAML parser version 0.9.0. Why not instead use a stable release of the 0.8.x branch (ie 0.8.11), which is currently the only stable version of it?

petrochenko-pavel-a commented 9 years ago

Actually it is not a snapshot already. But it is one of latest builds which has relative includes support as well as few other important bugfixes which I beleive are important. I will create PR for RAML parser fixing this and will try to get it integrating ASAP and move dependency to next RAML parser build 06 Мар 2015 г. 17:36 пользователь "David Dossot" notifications@github.com написал:

In that regard, it's a little scary that raml-for-jax-rs depends on a snapshot build of the RAML parser version 0.9.0. Why not instead use a stable release of the 0.8.x branch (ie 0.8.11), which is currently the only stable version of it?

— Reply to this email directly or view it on GitHub https://github.com/mulesoft/raml-for-jax-rs/issues/47#issuecomment-77589473 .

petrochenko-pavel-a commented 9 years ago

Hi Richard, the problem is that you ramp did not contains global schemas section. I have filed PR for it https://github.com/raml-org/raml-java-parser/pull/58

@ddossot : Actually it seems to be pretty old issue in Java Parser from what I am seeing it was introduced in commit dated on 2013-11-26

aldonline commented 9 years ago

Hello @richard-instil Thanks for filing this issue and sorry for the delay. We have been unable to reproduce this internally. Ideally we would need your exact setup ( JVM version, Maven version, RAML files, etc ). Can you share this with us? The issue seems to be related to parser internals ( instantiation + annotation processing ) and we haven't seen it happen before. We could just cover the specific NPE that hit you and release a patch, but we'd rather figure out the root cause. Thanks!

richard-instil commented 9 years ago

Unfortunately I can't pass on the RAML I was using as it is the property of a client. I do however believe the issue may have been a result of invalid RAML, rather than the missing schema node itself as I have been unable to recreate it with other files. I know when I opened the ticket I stated that the RAML was valid - and so I thought - but I have since found a couple of issues with schema definitions in it which may have resulted in some untoward behaviour. I am closing this ticket as I am satisfied that the parser operates as expected. Thanks for your help.

aldonline commented 9 years ago

Thanks @richard-instil . If you manage to find a way ( and the time ) to create a simple RAML file that reproduces the error we'd still like to take a look at it ;)