Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1149

NPE on getAnnotation() for not present in schema datatype

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.8.0
    • 2.8.1
    • None
    • All

    Description

      Run the following code:

      String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace='ns'>\n" +
      " <xs:element name=\"personnel\"/>\n" +
      "</xs:schema>";
      XsModelCreator creator = new XsModelCreator();
      SymbolTable symbolTable = new SymbolTable();
      InputSource src = new InputSource(new StringReader(content));
      src.setSystemId("fake");
      // Preparser setup.
      XMLGrammarPreparser preparser = new XMLGrammarPreparser(symbolTable);
      preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null); // Selects the grammar pool.
      XMLGrammarPool grammarPool= new XMLGrammarPoolImpl();
      preparser.setGrammarPool(grammarPool);
      preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(
      src.getPublicId(),
      src.getSystemId(),
      null,
      src.getCharacterStream(),
      src.getEncoding()));
      XSModel xsModel = creator.newXSModel(grammarPool);
      XSElementDeclaration elemDecl = xsModel.getElementDeclaration("personnel", "ns");
      XSComplexTypeDefinition typeDefinition = (XSComplexTypeDefinition) elemDecl.getTypeDefinition();
      XSWildcard attributeWildCard = typeDefinition.getAttributeWildcard();
      attributeWildCard.getAnnotation();//This should throw the NPE.

      As you can see, the personnel element has no associated data typed but it is mapped by default to anyType in the Xerces structure.
      This NPE also happens when getAnnotation() is called for nodes of types XSElementDeclaration, XSWildcard, XSModelGroup which do not actually appear in the schema (they can be obtained by exploring the XSComplexTypeDefinition of the anyType).

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            mrglavas@ca.ibm.com Michael Glavassevich
            radu_coravu Radu Coravu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment