Buggy code:
public class SchemaGrammar extends Grammar { private static final int CHUNK_SHIFT = 8 ; private static final int CHUNK_SIZE = 1 << ( SchemaGrammar . CHUNK_SHIFT ) ; private static final int CHUNK_MASK = ( SchemaGrammar . CHUNK_SIZE ) - 1 ; private static final int INITIAL_CHUNK_COUNT = 1 << ( 10 - ( SchemaGrammar . CHUNK_SHIFT ) ) ; private XMLContentSpec fTempContentSpecNode = new XMLContentSpec ( ) ; private XMLElementDecl fTempElementDecl = new XMLElementDecl ( ) ; private XMLAttributeDecl fTempAttributeDecl = new XMLAttributeDecl ( ) ; private int [ ] [ ] fScopeDefinedByElement = new int [ SchemaGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private String [ ] [ ] fFromAnotherSchemaURI = new String [ SchemaGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private ComplexTypeInfo [ ] [ ] fComplexTypeInfo = new TraverseSchema . ComplexTypeInfo [ SchemaGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private int [ ] [ ] fElementDeclDefaultType = new int [ SchemaGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private String [ ] [ ] fElementDeclDefaultValue = new String [ SchemaGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private int [ ] [ ] fElementDeclBlockSet = new int [ SchemaGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private int [ ] [ ] fElementDeclFinalSet = new int [ SchemaGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private int [ ] [ ] fElementDeclMiscFlags = new int [ SchemaGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private Hashtable fComplexTypeRegistry = null ; private Hashtable fAttributeDeclRegistry = null ; private DatatypeValidatorFactoryImpl fDatatypeRegistry = null ; Hashtable topLevelGroupDecls = new Hashtable ( ) ; Hashtable topLevelAttrDecls = new Hashtable ( ) ; Hashtable topLevelAttrGrpDecls = new Hashtable ( ) ; private NamespacesScope fNamespacesScope = null ; private String fTargetNamespaceURI = "" ; public NamespacesScope getNamespacesScope ( ) { } public String getTargetNamespaceURI ( ) { } public Hashtable getAttirubteDeclRegistry ( ) { } public Hashtable getComplexTypeRegistry ( ) { } public DatatypeValidatorFactoryImpl getDatatypeRegistry ( ) { } public int getElementDefinedScope ( int elementDeclIndex ) { } public int getElementDefaultTYpe ( int elementDeclIndex ) { } public int getElementDeclBlockSet ( int elementDeclIndex ) { } public int getElementDeclFinalSet ( int elementDeclIndex ) { } public int getElementDeclMiscFlags ( int elementDeclIndex ) { } public String getElementFromAnotherSchemaURI ( int elementDeclIndex ) { } public String getElementDefaultValue ( int elementDeclIndex ) { } public ComplexTypeInfo getElementComplexTypeInfo ( int elementDeclIndex ) { } protected void setAttributeDeclRegistry ( Hashtable attrReg ) { } protected void setComplexTypeRegistry ( Hashtable cTypeReg ) { } protected void setDatatypeRegistry ( DatatypeValidatorFactoryImpl dTypeReg ) { } protected void setNamespacesScope ( NamespacesScope nsScope ) { } protected void setTargetNamespaceURI ( String targetNSUri ) { } protected int createElementDecl ( ) { } protected void setElementDecl ( int elementDeclIndex , XMLElementDecl elementDecl ) { } protected int createContentSpec ( ) { } protected void setContentSpec ( int contentSpecIndex , XMLContentSpec contentSpec ) { } protected int createAttributeDecl ( ) { } protected void setAttributeDecl ( int elementDeclIndex , int attributeDeclIndex , XMLAttributeDecl attributeDecl ) { } protected void setElementDefinedScope ( int elementDeclIndex , int scopeDefined ) { } protected void setElementFromAnotherSchemaURI ( int elementDeclIndex , String anotherSchemaURI ) { } protected void setElementComplexTypeInfo ( int elementDeclIndex , TraverseSchema . ComplexTypeInfo typeInfo ) { } protected void setElementDefault ( int elementDeclIndex , int defaultType , String defaultValue ) { } protected void setElementDeclBlockSet ( int elementDeclIndex , int blockSet ) { } protected void setElementDeclFinalSet ( int elementDeclIndex , int finalSet ) { } protected void setElementDeclMiscFlags ( int elementDeclIndex , int miscFlags ) { } protected int addElementDecl ( QName eltQName , int enclosingScope , int scopeDefined , int contentSpecType , int contentSpecIndex , int attrListHead , DatatypeValidator dv ) { <START_BUG> int elementDeclIndex = getElementDeclIndex ( eltQName . localpart , enclosingScope ) ; <END_BUG> if ( elementDeclIndex == ( - 1 ) ) { if ( ( enclosingScope < ( - 1 ) ) || ( scopeDefined < ( - 1 ) ) ) { } fTempElementDecl . name . setValues ( eltQName ) ; fTempElementDecl . enclosingScope = enclosingScope ; fTempElementDecl . type = contentSpecType ; fTempElementDecl . contentSpecIndex = contentSpecIndex ; fTempElementDecl . datatypeValidator = dv ; elementDeclIndex = createElementDecl ( ) ; setElementDecl ( elementDeclIndex , fTempElementDecl ) ; setFirstAttributeDeclIndex ( elementDeclIndex , attrListHead ) ; setElementDefinedScope ( elementDeclIndex , scopeDefined ) ; } return elementDeclIndex ; } protected void addAttDef ( int templateElementIndex , QName attQName , int attType , int enumeration , int attDefaultType , String attDefaultValue , DatatypeValidator dv ) { } public int getAttributeDeclIndex ( int elementIndex , QName attribute ) { } protected int addContentSpecNode ( int contentSpecType , int value , int otherValue , boolean mustBeUnique ) { } private boolean ensureElementDeclCapacity ( int chunk ) { } private int [ ] [ ] resize ( int [ ] [ ] array , int newsize ) { } private DatatypeValidator [ ] [ ] resize ( DatatypeValidator [ ] [ ] array , int newsize ) { } private XMLContentModel [ ] [ ] resize ( XMLContentModel [ ] [ ] array , int newsize ) { } private QName [ ] [ ] resize ( QName [ ] [ ] array , int newsize ) { } private String [ ] [ ] resize ( String [ ] [ ] array , int newsize ) { } private ComplexTypeInfo [ ] [ ] resize ( TraverseSchema [ ] [ ] array , int newsize ) { } }

Fix:
int elementDeclIndex = getElementDeclIndex ( eltQName , enclosingScope ) ;