Buggy code:
private String [ ] [ ] fLocalElemNamespaceContext = new String [ XSDHandler . INIT_STACK_SIZE ] [ 1 ] ; private static final int INIT_KEYREF_STACK = 2 ; private static final int INC_KEYREF_STACK_AMOUNT = 2 ; private int fKeyrefStackPos = 0 ; private Element [ ] fKeyrefs = new Element [ XSDHandler . INIT_KEYREF_STACK ] ; private XSElementDecl [ ] fKeyrefElems = new XSElementDecl [ XSDHandler . INIT_KEYREF_STACK ] ; private String [ ] [ ] fKeyrefNamespaceContext = new String [ XSDHandler . INIT_KEYREF_STACK ] [ 1 ] ; public XSDHandler ( XSGrammarBucket gBucket ) { } public SchemaGrammar parseSchema ( XSDDescription desc ) { } public SchemaGrammar parseSchema ( XMLInputSource is , XSDDescription desc ) { } protected SchemaGrammar findGrammar ( XSDDescription desc ) { } private static final String [ ] [ ] NS_ERROR_CODES = new String [ ] [ ] { new String [ ] { "src-include.2.1" , "src-include.2.1" } , new String [ ] { "src-redefine.3.1" , "src-redefine.3.1" } , new String [ ] { "src-import.3.1" , "src-import.3.2" } , null , new String [ ] { "TargetNamespace.1" , "TargetNamespace.2" } , new String [ ] { "TargetNamespace.1" , "TargetNamespace.2" } , new String [ ] { "TargetNamespace.1" , "TargetNamespace.2" } , new String [ ] { "TargetNamespace.1" , "TargetNamespace.2" } } ; private static final String [ ] ELE_ERROR_CODES = new String [ ] { "src-include.1" , "src-redefine.2" , "src-import.2" , "schema_reference.4" , "schema_reference.4" , "schema_reference.4" , "schema_reference.4" , "schema_reference.4" } ; protected XSDocumentInfo constructTrees ( Document schemaRoot , String locationHint , XSDDescription desc ) { if ( schemaRoot == null ) return null ; String callerTNS = desc . getTargetNamespace ( ) ; short referType = desc . getContextType ( ) ; XSDocumentInfo currSchemaInfo = null ; try { currSchemaInfo = new XSDocumentInfo ( schemaRoot , fAttributeChecker , fSymbolTable ) ; } catch ( XMLSchemaException se ) { reportSchemaError ( XSDHandler . ELE_ERROR_CODES [ referType ] , new Object [ ] { locationHint } , DOMUtil . getRoot ( schemaRoot ) ) ; return null ; } if ( ( ( currSchemaInfo . fTargetNamespace ) != null ) && ( ( currSchemaInfo . fTargetNamespace . length ( ) ) == 0 ) ) { reportSchemaWarning ( "EmptyTargetNamespace" , new Object [ ] { locationHint } , DOMUtil . getRoot ( schemaRoot ) ) ; currSchemaInfo . fTargetNamespace = null ; } if ( callerTNS != null ) { int secondIdx = 0 ; if ( ( referType == ( XSDDescription . CONTEXT_INCLUDE ) ) || ( referType == ( XSDDescription . CONTEXT_REDEFINE ) ) ) { if ( ( currSchemaInfo . fTargetNamespace ) == null ) { currSchemaInfo . fTargetNamespace = callerTNS ; currSchemaInfo . fIsChameleonSchema = true ; } else if ( callerTNS != ( currSchemaInfo . fTargetNamespace ) ) { reportSchemaError ( XSDHandler . NS_ERROR_CODES [ referType ] [ secondIdx ] , new Object [ ] { callerTNS , currSchemaInfo . fTargetNamespace } , DOMUtil . getRoot ( schemaRoot ) ) ; return null ; } } else if ( callerTNS != ( currSchemaInfo . fTargetNamespace ) ) { reportSchemaError ( XSDHandler . NS_ERROR_CODES [ referType ] [ secondIdx ] , new Object [ ] { callerTNS , currSchemaInfo . fTargetNamespace } , DOMUtil . getRoot ( schemaRoot ) ) ; return null ; } } else if ( ( currSchemaInfo . fTargetNamespace ) != null ) { if ( referType == ( XSDDescription . CONTEXT_PREPARSE ) ) { desc . setTargetNamespace ( currSchemaInfo . fTargetNamespace ) ; callerTNS = currSchemaInfo . fTargetNamespace ; } else { int secondIdx = 1 ; reportSchemaError ( XSDHandler . NS_ERROR_CODES [ referType ] [ secondIdx ] , new Object [ ] { callerTNS , currSchemaInfo . fTargetNamespace } , DOMUtil . getRoot ( schemaRoot ) ) ; return null ; } } currSchemaInfo . addAllowedNS ( currSchemaInfo . fTargetNamespace ) ; SchemaGrammar sg = null ; if ( ( referType != ( XSDDescription . CONTEXT_INCLUDE ) ) && ( referType != ( XSDDescription . CONTEXT_REDEFINE ) ) ) { <START_BUG> sg = new SchemaGrammar ( fSymbolTable , currSchemaInfo . fTargetNamespace , desc . makeClone ( ) ) ; <END_BUG> fGrammarBucket . putGrammar ( sg ) ; } fDoc2XSDocumentMap . put ( schemaRoot , currSchemaInfo ) ; Vector dependencies = new Vector ( ) ; Element rootNode = DOMUtil . getRoot ( schemaRoot ) ; Document newSchemaRoot = null ; for ( Element child = DOMUtil . getFirstChildElement ( rootNode ) ; child != null ; child = DOMUtil . getNextSiblingElement ( child ) ) { String schemaNamespace = null ; String schemaHint = null ; String localName = DOMUtil . getLocalName ( child ) ; short refType = - 1 ; if ( localName . equals ( ELT_ANNOTATION ) ) continue ; else if ( localName . equals ( ELT_IMPORT ) ) { refType = XSDDescription . CONTEXT_IMPORT ; Object [ ] includeAttrs = fAttributeChecker . checkAttributes ( child , true , currSchemaInfo ) ; schemaHint = ( ( String ) ( includeAttrs [ XSAttributeChecker . ATTIDX_SCHEMALOCATION ] ) ) ; schemaNamespace = ( ( String ) ( includeAttrs [ XSAttributeChecker . ATTIDX_NAMESPACE ] ) ) ; if ( schemaNamespace != null ) schemaNamespace = fSymbolTable . addSymbol ( schemaNamespace ) ; if ( schemaNamespace == ( currSchemaInfo . fTargetNamespace ) ) { reportSchemaError ( "src-import.1.1" , new Object [ ] { schemaNamespace } , child ) ; } fAttributeChecker . returnAttrArray ( includeAttrs , currSchemaInfo ) ; if ( currSchemaInfo . isAllowedNS ( schemaNamespace ) ) continue ; currSchemaInfo . addAllowedNS ( schemaNamespace ) ; String tns = null2EmptyString ( currSchemaInfo . fTargetNamespace ) ; Vector ins = ( ( Vector ) ( fImportMap . get ( tns ) ) ) ; if ( ins == null ) { fAllTNSs . addElement ( tns ) ; ins = new Vector ( ) ; fImportMap . put ( tns , ins ) ; ins . addElement ( schemaNamespace ) ; }

Fix:
sg = new SchemaGrammar ( currSchemaInfo . fTargetNamespace , desc . makeClone ( ) ) ;