Buggy code:
private static final int INITIAL_CHUNK_COUNT = 1 << ( 10 - ( DTDGrammar . CHUNK_SHIFT ) ) ; private StringPool fStringPool ; private XMLElementDecl fElementDecl = new XMLElementDecl ( ) ; private XMLAttributeDecl fAttributeDecl = new XMLAttributeDecl ( ) ; private XMLContentSpec fContentSpec = new XMLContentSpec ( ) ; private Document fGrammarDocument ; private Element fRootElement ; private QName fRootElementQName = new QName ( ) ; private Element fCurrentElement ; private int [ ] [ ] fElementDeclIsExternal = new int [ DTDGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private int [ ] [ ] fElementDeclMap = new int [ DTDGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private int [ ] [ ] fAttributeDeclIsExternal = new int [ DTDGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private int [ ] [ ] fAttributeDeclMap = new int [ DTDGrammar . INITIAL_CHUNK_COUNT ] [ ] ; private int [ ] [ ] fContentSpecMap = new int [ DTDGrammar . INITIAL_CHUNK_COUNT ] [ ] ; public DTDGrammar ( StringPool stringPool ) { } public void reset ( StringPool stringPool ) { } public void callStartDTD ( ) throws Exception { } public void callEndDTD ( ) throws Exception { } public void callTextDecl ( int version , int encoding ) throws Exception { } public void doctypeDecl ( QName rootElement , int publicId , int systemId ) throws Exception { } public void startReadingFromExternalSubset ( int publicId , int systemId ) throws Exception { } public void stopReadingFromExternalSubset ( ) throws Exception { } public int addElementDecl ( QName elementDecl ) throws Exception { } public int addElementDecl ( QName elementDecl , int contentSpecType , int contentSpec , boolean isExternal ) throws Exception { } public void setElementDeclDTD ( int elementDeclIndex , XMLElementDecl elementDecl ) { } public void setElementDeclIsExternal ( int elementDeclIndex , boolean isExternal ) { } public boolean getElementDeclIsExternal ( int elementDeclIndex ) { } public boolean getAttributeDeclIsExternal ( int attributeDeclIndex ) { } public boolean getRootElementQName ( QName root ) { } public int addAttDef ( QName elementDecl , QName attributeDecl , int attType , boolean attList , int enumeration , int attDefaultType , int attDefaultValue , boolean isExternal ) throws Exception { Element attributeDeclElement = fGrammarDocument . createElement ( "attributeDecl" ) ; attributeDeclElement . setAttribute ( "element" , fStringPool . toString ( elementDecl . localpart ) ) ; attributeDeclElement . setAttribute ( "name" , fStringPool . toString ( attributeDecl . localpart ) ) ; if ( ( attributeDecl . uri ) != ( - 1 ) ) { attributeDeclElement . setAttribute ( ( "xmlns:" + ( fStringPool . toString ( attributeDecl . prefix ) ) ) , fStringPool . toString ( attributeDecl . uri ) ) ; } attributeDeclElement . setAttribute ( "type" , fStringPool . toString ( attType ) ) ; attributeDeclElement . setAttribute ( "defaultType" , fStringPool . toString ( attDefaultType ) ) ; attributeDeclElement . setAttribute ( "defaultValue" , fStringPool . toString ( attDefaultValue ) ) ; fCurrentElement . appendChild ( attributeDeclElement ) ; int attributeDeclIndex = createAttributeDecl ( ) ; String attTypeString = "" ; switch ( attType ) { case XMLAttributeDecl . TYPE_CDATA : attTypeString = "string" ; case XMLAttributeDecl . TYPE_ENTITY : attTypeString = "ENTITY" ; case XMLAttributeDecl . TYPE_ENUMERATION : attTypeString = "ENUMERATION" ; case XMLAttributeDecl . TYPE_ID : attTypeString = "ID" ; case XMLAttributeDecl . TYPE_IDREF : attTypeString = "IDREF" ; case XMLAttributeDecl . TYPE_NMTOKEN : attTypeString = "NMTOKEN" ; case XMLAttributeDecl . TYPE_NOTATION : attTypeString = "NOTATION" ; default : } fAttributeDecl . clear ( ) ; fAttributeDecl . name . setValues ( attributeDecl ) ; fAttributeDecl . type = attType ; fAttributeDecl . list = attList ; fAttributeDecl . enumeration = enumeration ; fAttributeDecl . datatypeValidator = DatatypeValidatorFactoryImpl . getDatatypeRegistry ( ) . getDatatypeValidator ( attTypeString ) ; fAttributeDecl . defaultType = attDefaultType ; fAttributeDecl . defaultValue = fStringPool . toString ( attDefaultValue ) ; <START_BUG> int elementDeclIndex = getElementDeclIndex ( elementDecl . localpart , ( - 1 ) ) ; <END_BUG> setAttributeDecl ( elementDeclIndex , attributeDeclIndex , fAttributeDecl ) ; int chunk = attributeDeclIndex > > ( DTDGrammar . CHUNK_SHIFT ) ; int index = attributeDeclIndex & ( DTDGrammar . CHUNK_MASK ) ; ensureAttributeDeclCapacity ( chunk ) ; fAttributeDeclIsExternal [ chunk ] [ index ] = ( isExternal ) ? 1 : 0 ; return attributeDeclIndex ; } public int addUniqueLeafNode ( int nameIndex ) throws Exception { } public int addContentSpecNode ( int nodeType , int nodeValue ) throws Exception { } public int addContentSpecNode ( int nodeType , int leftNodeIndex , int rightNodeIndex ) throws Exception { } public String getContentSpecNodeAsString ( int nodeIndex ) throws Exception { } public boolean startEntityDecl ( boolean isPE , int entityName ) throws Exception { } public void endEntityDecl ( ) throws Exception { } public int addInternalPEDecl ( int name , int value ) throws Exception { } public int addExternalPEDecl ( int name , int publicId , int systemId ) throws Exception { } public int addInternalEntityDecl ( int name , int value ) throws Exception { } public int addExternalEntityDecl ( int name , int publicId , int systemId ) throws Exception { } public int addUnparsedEntityDecl ( int name , int publicId , int systemId , int notationName ) throws Exception { } public int startEnumeration ( ) throws Exception { } public void addNameToEnumeration ( int enumIndex , int elementType , int attrName , int nameIndex , boolean isNotationType ) throws Exception { } public void endEnumeration ( int enumIndex ) throws Exception { } public int addNotationDecl ( int notationName , int publicId , int systemId ) throws Exception { } public void callComment ( int data ) throws Exception { } public void callProcessingInstruction ( int piTarget , int piData ) throws Exception { } public void internalSubset ( int internalSubset ) throws Exception { } private boolean ensureElementDeclCapacity ( int chunk ) { } private boolean ensureAttributeDeclCapacity ( int chunk ) { } private boolean ensureContentSpecCapacity ( int chunk ) { }

Fix:
int elementDeclIndex = getElementDeclIndex ( elementDecl , ( - 1 ) ) ;