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

ResourceDoclet: MarshallException and NullPointerException with MethodTree, wadl-doclet 3.0.4/2.35 #5017

Open
johnmarquez12 opened this issue Mar 29, 2022 · 7 comments · Fixed by #5024

Comments

@johnmarquez12
Copy link
Contributor

Running into the following errors in my gradle task using ant.javadoc. This was after upgrading to Java 17 and jersey-wadl-doclet:3.0.4:

[ant:javadoc] SEVERE: Could not serialize ResourceDoc.
[ant:javadoc] jakarta.xml.bind.MarshalException
[ant:javadoc]  - with linked exception:
[ant:javadoc] [com.sun.istack.SAXException2: unable to marshal type "org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType" as an element because it is missing an @XmlRootElement annotation]
[ant:javadoc] 	at org.glassfish.jaxb.runtime.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:271)
[ant:javadoc] 	at org.glassfish.jaxb.runtime.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:196)
[ant:javadoc] 	at jakarta.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:101)
[ant:javadoc] 	at org.glassfish.jersey.wadl.doclet.DocletUtils.createOutputFile(DocletUtils.java:105)
[ant:javadoc] 	at org.glassfish.jersey.wadl.doclet.ResourceDoclet.run(ResourceDoclet.java:190)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Start.parseAndExecute(Start.java:556)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:393)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:342)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Main.execute(Main.java:63)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Main.main(Main.java:52)
[ant:javadoc] Caused by: com.sun.istack.SAXException2: unable to marshal type "org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType" as an element because it is missing an @XmlRootElement annotation
[ant:javadoc] error: fatal error encountered: java.lang.NullPointerException: Cannot invoke "com.sun.source.tree.MethodTree.getName()" because "methodTree" is null
[ant:javadoc] error: Please file a bug against the javadoc tool via the Java bug reporting page
[ant:javadoc]   (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com)
[ant:javadoc]   for duplicates. Include error messages and the following diagnostic in your report. Thank you.
[ant:javadoc] java.lang.NullPointerException: Cannot invoke "com.sun.source.tree.MethodTree.getName()" because "methodTree" is null
[ant:javadoc] 	at org.glassfish.jersey.wadl.doclet.ResourceDoclet.run(ResourceDoclet.java:165)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Start.parseAndExecute(Start.java:556)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:393)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:342)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Main.execute(Main.java:63)
[ant:javadoc] 	at jdk.javadoc/jdk.javadoc.internal.tool.Main.main(Main.java:52)
[ant:javadoc] 2 errors

we're currently also using jersey-server:2.26 and 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'

@senivam
Copy link
Contributor

senivam commented Mar 30, 2022

Please consider updating jersey-server to 3.0.4 as well. Because org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType is part of jersey-server and it has javax annotated XmlRootElement whether you need jakarta annotated XmlRootElement which is a part of jersey-server 3.0.4.

@jansupol
Copy link
Contributor

Please do not mix Jersey 2.x, JAX-B/2, JAX-RS 2.x with Jersey 3.x, JAX-B/3, and JAX-RS 3.x.

@johnmarquez12
Copy link
Contributor Author

Please consider updating jersey-server to 3.0.4 as well. Because org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType is part of jersey-server and it has javax annotated XmlRootElement whether you need jakarta annotated XmlRootElement which is a part of jersey-server 3.0.4.

Thanks this fixed the first error, however I'm still running into the 2nd error.

@jansupol
Copy link
Contributor

Would you be able to provide a reproducer?

@johnmarquez12
Copy link
Contributor Author

Would you be able to provide a reproducer?

Not sure how much I'll be able to provide but heres my gradle task:

// use ant.javadoc instead of gradle's javadoc plugin, due to https://github.com/gradle/gradle/issues/4530
    doLast {
        ant.javadoc(sourcepath: sourceSets.main.java.srcDirs.join(':'),
                    classpath: configurations.toolsImplementation.asPath + ":" + sourceSets.tools.output.classesDirs.join(':'),
                    packagenames: "some.package.server.rest.*",
                    defaultexcludes: "yes",
                    version: "true",
                    maxmemory: "512m",
                    useexternalfile: "yes",
                    failonerror: "yes") {
            doclet(name: "org.glassfish.jersey.wadl.doclet.ResourceDoclet", path: configurations.toolsImplementation.asPath + ":" + sourceSets.tools.output.classesDirs.join(':')) {
                param(name: "-output", value: "${javadocDir}/resourcedoc.xml")
                param(name: "-processors", value: "some.package.tools.CustomDocProcessor")
            }
        }
        copy {
            from javadocDir
            into restResource
            include "*.xml"
        }
    }

it fails during the ant task.

The CustomDocProcessor:

public class CustomDocProcessor implements DocProcessor {
    /**
     * Add the ResourceDocProperty class to the jaxbContext classes.
     */
    @Override
    public Class<?>[] getRequiredJaxbContextClasses() {
        List<Class<?>> classes = Arrays.<Class<?>>asList(ResourceDocProperty.class);
        return classes.toArray(new Class<?>[classes.size()]);
    }

    @Override
    public String[] getCDataElements() {
        return new String[0];
    }

    /**
     * Adds any @ClassTitle annotation to the class doc.
     */
    @Override
    public void processClassDoc(TypeElement classDoc, ClassDocType classDocType) {
        ClassTitle title = classDoc.getAnnotation(ClassTitle.class);
        if (title != null) {
            classDocType.getAny().add(new ResourceDocProperty("title", title.value()));
        }
    }

    /**
     * Adds any @MethodTitle annotations to the method doc.
     */
    @Override
    public void processMethodDoc(ExecutableElement methodDoc, MethodDocType methodDocType) {
        MethodTitle title = methodDoc.getAnnotation(MethodTitle.class);
        if (title != null) {
            methodDocType.getAny().add(new ResourceDocProperty("title", title.value()));
        }
    }

    @Override
    public void processParamTag(VariableElement paramTag, ParamDocType paramDocType) {
    }
}

@johnmarquez12
Copy link
Contributor Author

johnmarquez12 commented Mar 31, 2022

Looks like a simple null check should be ok, I copied the wadl-doclet classes and added it, seems to runs fine for our use:

MethodDocType methodDocType = new MethodDocType();
methodDocType.setMethodName(methodTree.getName().toString());
methodDocType.setCommentText(getComments(docTrees.getDocCommentTree(method)));
getTags(docTrees.getDocCommentTree(method));

...
if (methodTree != null) {
    methodDocType.setMethodName(methodTree.getName().toString());
    methodDocType.setCommentText(getComments(docTrees.getDocCommentTree(method)));
}

@johnmarquez12 johnmarquez12 changed the title ResourceDoclet MarshalException on wadl-doclet 3.0.4 ResourceDoclet: MarshallException and NullPointerException with MethodTree, wadl-doclet 3.0.4/2.35 Mar 31, 2022
@jansupol
Copy link
Contributor

jansupol commented Apr 1, 2022

@johnmarquez12 That is cool. Feel free to provide a PR to Jersey

@jansupol jansupol linked a pull request Apr 8, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants