You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by ji...@apache.org on 2004/05/19 23:42:01 UTC

[jira] Assigned: (XERCESJ-968) Null pointer exception in XSModel.getAnnotations() method

Message:

   The following issue has been re-assigned.

   Assignee: Michael Glavassevich (mailto:mrglavas@ca.ibm.com)
---------------------------------------------------------------------
View the issue:
  http://issues.apache.org/jira/browse/XERCESJ-968

Here is an overview of the issue:
---------------------------------------------------------------------
        Key: XERCESJ-968
    Summary: Null pointer exception in XSModel.getAnnotations() method
       Type: Bug

     Status: Open
   Priority: Major

    Project: Xerces2-J
 Components: 
             XML Schema Structures
   Versions:
             2.6.2

   Assignee: Michael Glavassevich
   Reporter: Alex Kutovoy

    Created: Wed, 19 May 2004 2:13 PM
    Updated: Wed, 19 May 2004 2:41 PM
Environment: Windows 2000, JDK 1.4.1_02, Xerces-2.6.2, compiled for DOM3 level

Description:
I was tryring to run the following code, loading the sample schema 'po.xsd' (shown below):

public class XSModelTest
{
  public static void main(String[] args) {
    try {
      // Get DOM Implementation using DOM Registry
      System.setProperty(DOMImplementationRegistry.PROPERTY,
      "org.apache.xerces.dom.DOMXSImplementationSourceImpl");

       DOMImplementationRegistry registry =
         DOMImplementationRegistry.newInstance();

       XSImplementation impl =
         (XSImplementation) registry.getDOMImplementation("XS-Loader");

       XSLoader schemaLoader = impl.createXSLoader(null);
       XSModel schema = schemaLoader.loadURI("po.xsd");

       XSObjectList annotations = schema.getAnnotations();
       int annotCount = annotations.getLength();
}

I stripped down the schema file to highlight the problem:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:annotation>
  <xsd:documentation xml:lang="en">
   Purchase order schema for Example.com.
   Copyright 2000 Example.com. All rights reserved.
  </xsd:documentation>
 </xsd:annotation>
 <xsd:element name="comment" type="xsd:string"/>
</xsd:schema>

The schema loads just fine, but the call to schema.getAnnotations() results in Null pointer exception with the following trace:

java.lang.NullPointerException
  at java.lang.System.arraycopy(Native Method)
  at org.apache.xerces.impl.xs.XSModelImpl.getAnnotations
  at XSModelTest.main(XSModelTest.java:42)

I inspected the code and found the following (which looks like a bug to me):


for (int i = 0; i < fGrammarCount; i++) {
  SchemaGrammar currGrammar = fGrammarList[i];
  System.arraycopy(currGrammar.fAnnotations, 0, annotations, currPos, currGrammar.fNumAnnotations);
  currPos += currGrammar.fNumAnnotations;
  }
}

The for-loop iterates over the list of SchemaGrammars and attempts to copy currGrammar.fAnnotations into the pre-allocated array. The code does NOT verify that fAnnotations member is not null. If the current grammar does not have any annotations, this member is null and arraycopy fails.

I added check for null, and the code worked fine after that. 

Am I missing something or is this a bug?


Alex K.





---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org