QDox
  1. QDox
  2. QDOX-253

DefaultJavaAnnotationAssembler throws a NPE exception

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-alpha
    • Fix Version/s: 2.0
    • Component/s: Parser
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Given a class is parsed.
      Given that class has a constructor.
      Given the constructor has parameters.
      Given some parameters have an annotation.
      When parsing the file.
      Then a NPE exception is thrown.

      NPE stack is

      Exception in thread "main" java.lang.NullPointerException
      	at com.thoughtworks.qdox.model.impl.DefaultJavaParameter.getParentClass(DefaultJavaParameter.java:91)
      	at com.thoughtworks.qdox.builder.impl.DefaultJavaAnnotationAssembler.createType(DefaultJavaAnnotationAssembler.java:145)
      	at com.thoughtworks.qdox.builder.impl.DefaultJavaAnnotationAssembler.assemble(DefaultJavaAnnotationAssembler.java:123)
      	at com.thoughtworks.qdox.builder.impl.ModelBuilder.setAnnotations(ModelBuilder.java:478)
      	at com.thoughtworks.qdox.builder.impl.ModelBuilder.addParameter(ModelBuilder.java:465)
      	at com.thoughtworks.qdox.parser.impl.Parser.yyparse(Parser.java:2312)
      	at com.thoughtworks.qdox.parser.impl.Parser.parse(Parser.java:1575)
      	at com.thoughtworks.qdox.library.SourceLibrary.parse(SourceLibrary.java:205)
      	at com.thoughtworks.qdox.library.SourceLibrary.parse(SourceLibrary.java:181)
      	at com.thoughtworks.qdox.library.SourceLibrary.addSource(SourceLibrary.java:138)
      	at com.thoughtworks.qdox.library.SortedClassLibraryBuilder.addSource(SortedClassLibraryBuilder.java:173)
      	at com.thoughtworks.qdox.JavaProjectBuilder.addSource(JavaProjectBuilder.java:150)
      

        Activity

        Hide
        Iulian Zuzu added a comment -

        The above, makes classes described by the Gerkin statement be un-parseable.

        Show
        Iulian Zuzu added a comment - The above, makes classes described by the Gerkin statement be un-parseable.
        Robert Scholte made changes -
        Field Original Value New Value
        Description Given a class is parsed.
        Given that class has a constructor.
        Given the constructor has parameters.
        Given some parameters have an annotation.
        When parsing the file.
        Then a NPE exception is thrown.

        NPE stack is

        Exception in thread "main" java.lang.NullPointerException
        at com.thoughtworks.qdox.model.impl.DefaultJavaParameter.getParentClass(DefaultJavaParameter.java:91)
        at com.thoughtworks.qdox.builder.impl.DefaultJavaAnnotationAssembler.createType(DefaultJavaAnnotationAssembler.java:145)
        at com.thoughtworks.qdox.builder.impl.DefaultJavaAnnotationAssembler.assemble(DefaultJavaAnnotationAssembler.java:123)
        at com.thoughtworks.qdox.builder.impl.ModelBuilder.setAnnotations(ModelBuilder.java:478)
        at com.thoughtworks.qdox.builder.impl.ModelBuilder.addParameter(ModelBuilder.java:465)
        at com.thoughtworks.qdox.parser.impl.Parser.yyparse(Parser.java:2312)
        at com.thoughtworks.qdox.parser.impl.Parser.parse(Parser.java:1575)
        at com.thoughtworks.qdox.library.SourceLibrary.parse(SourceLibrary.java:205)
        at com.thoughtworks.qdox.library.SourceLibrary.parse(SourceLibrary.java:181)
        at com.thoughtworks.qdox.library.SourceLibrary.addSource(SourceLibrary.java:138)
        at com.thoughtworks.qdox.library.SortedClassLibraryBuilder.addSource(SortedClassLibraryBuilder.java:173)
        at com.thoughtworks.qdox.JavaProjectBuilder.addSource(JavaProjectBuilder.java:150)


        Given a class is parsed.
        Given that class has a constructor.
        Given the constructor has parameters.
        Given some parameters have an annotation.
        When parsing the file.
        Then a NPE exception is thrown.

        NPE stack is
        {noformat}
        Exception in thread "main" java.lang.NullPointerException
        at com.thoughtworks.qdox.model.impl.DefaultJavaParameter.getParentClass(DefaultJavaParameter.java:91)
        at com.thoughtworks.qdox.builder.impl.DefaultJavaAnnotationAssembler.createType(DefaultJavaAnnotationAssembler.java:145)
        at com.thoughtworks.qdox.builder.impl.DefaultJavaAnnotationAssembler.assemble(DefaultJavaAnnotationAssembler.java:123)
        at com.thoughtworks.qdox.builder.impl.ModelBuilder.setAnnotations(ModelBuilder.java:478)
        at com.thoughtworks.qdox.builder.impl.ModelBuilder.addParameter(ModelBuilder.java:465)
        at com.thoughtworks.qdox.parser.impl.Parser.yyparse(Parser.java:2312)
        at com.thoughtworks.qdox.parser.impl.Parser.parse(Parser.java:1575)
        at com.thoughtworks.qdox.library.SourceLibrary.parse(SourceLibrary.java:205)
        at com.thoughtworks.qdox.library.SourceLibrary.parse(SourceLibrary.java:181)
        at com.thoughtworks.qdox.library.SourceLibrary.addSource(SourceLibrary.java:138)
        at com.thoughtworks.qdox.library.SortedClassLibraryBuilder.addSource(SortedClassLibraryBuilder.java:173)
        at com.thoughtworks.qdox.JavaProjectBuilder.addSource(JavaProjectBuilder.java:150)
        {noformat}

        Hide
        Robert Scholte added a comment -

        Would be nice if you could write a unittest for this, including the expected value(s). /Old_Qdox_Issues/index.html#selectedTab=com.atlassian.jira.plugin.system.project%3Asummary-panel describes how you can easily write one.

        Show
        Robert Scholte added a comment - Would be nice if you could write a unittest for this, including the expected value(s). /Old_Qdox_Issues/index.html#selectedTab=com.atlassian.jira.plugin.system.project%3Asummary-panel describes how you can easily write one.
        Hide
        Tai Le added a comment -

        Here is the test for QDox 2.0-M1. If you remove the @Value annotation, it' ok. But when we have that annotation, it throws NPE.

        @Test
            public void testConstructorHasAnnotation() throws Exception {
                JavaProjectBuilder builder = new JavaProjectBuilder();
                String source = "public class Foo { private String apiPath; public Foo(@Value(\"${api.path}\") String apiPath) {this.apiPath = apiPath}}";
                builder.addSource( new StringReader(source) );
            }
        
        Show
        Tai Le added a comment - Here is the test for QDox 2.0-M1. If you remove the @Value annotation, it' ok. But when we have that annotation, it throws NPE. @Test public void testConstructorHasAnnotation() throws Exception { JavaProjectBuilder builder = new JavaProjectBuilder(); String source = " public class Foo { private String apiPath; public Foo(@Value(\" ${api.path}\ ") String apiPath) { this .apiPath = apiPath}}" ; builder.addSource( new StringReader(source) ); }
        Hide
        Robert Scholte added a comment -

        Fixed in rev.1583
        Nice catch, this exposed some other minor problems with constructors as well.

        Show
        Robert Scholte added a comment - Fixed in rev.1583 Nice catch, this exposed some other minor problems with constructors as well.
        Robert Scholte made changes -
        Resolution Fixed [ 1 ]
        Assignee Robert Scholte [ rfscholte ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Iulian Zuzu added a comment -

        Hi all,

        Thanks a lot for having this done. Any estimation on when a new release will be available including this fix?

        Thanks,
        Iulian

        Show
        Iulian Zuzu added a comment - Hi all, Thanks a lot for having this done. Any estimation on when a new release will be available including this fix? Thanks, Iulian
        Hide
        Robert Scholte added a comment -

        2.0-M2 is now available at Maven Central

        Show
        Robert Scholte added a comment - 2.0-M2 is now available at Maven Central

          People

          • Assignee:
            Robert Scholte
            Reporter:
            Iulian Zuzu
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: