Message: A new issue has been created in JIRA.
--------------------------------------------------------------------- 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: Unassigned Priority: Major Project: Xerces2-J Components: XML Schema Structures Versions: 2.6.2 Assignee: Reporter: Alex Kutovoy Created: Wed, 19 May 2004 2:13 PM Updated: Wed, 19 May 2004 2:13 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
