Buggy code:
QName subGroupAtt = ( ( QName ) ( attrValues [ XSAttributeChecker . ATTIDX_SUBSGROUP ] ) ) ; QName typeAtt = ( ( QName ) ( attrValues [ XSAttributeChecker . ATTIDX_TYPE ] ) ) ; XSElementDecl element = new XSElementDecl ( ) ; if ( nameAtt != null ) element . fName = fSymbolTable . addSymbol ( nameAtt ) ; if ( isGlobal ) { element . fTargetNamespace = schemaDoc . fTargetNamespace ; } else if ( formAtt != null ) { if ( ( formAtt . intValue ( ) ) == ( SchemaSymbols . FORM_QUALIFIED ) ) element . fTargetNamespace = schemaDoc . fTargetNamespace ; else element . fTargetNamespace = null ; } else if ( schemaDoc . fAreLocalElementsQualified ) { element . fTargetNamespace = schemaDoc . fTargetNamespace ; } else { element . fTargetNamespace = null ; } element . fBlock = ( blockAtt == null ) ? schemaDoc . fBlockDefault : blockAtt . shortValue ( ) ; element . fFinal = ( finalAtt == null ) ? schemaDoc . fFinalDefault : finalAtt . shortValue ( ) ; if ( nillableAtt . booleanValue ( ) ) element . setIsNillable ( ) ; if ( ( abstractAtt != null ) && ( abstractAtt . booleanValue ( ) ) ) element . setIsAbstract ( ) ; if ( fixedAtt != null ) { element . fDefault = fixedAtt ; element . setConstraintType ( FIXED_VALUE ) ; } else if ( defaultAtt != null ) { element . fDefault = defaultAtt ; element . setConstraintType ( DEFAULT_VALUE ) ; } else { element . setConstraintType ( NO_CONSTRAINT ) ; } if ( subGroupAtt != null ) { element . fSubGroup = ( ( XSElementDecl ) ( fSchemaHandler . getGlobalDecl ( schemaDoc , ELEMENT_TYPE , subGroupAtt ) ) ) ; } Element child = DOMUtil . getFirstChildElement ( elmDecl ) ; if ( ( child != null ) && ( DOMUtil . getLocalName ( child ) . equals ( ELT_ANNOTATION ) ) ) { traverseAnnotationDecl ( child , attrValues , false , schemaDoc ) ; child = DOMUtil . getNextSiblingElement ( child ) ; } XSTypeDecl elementType = null ; boolean haveAnonType = false ; if ( child != null ) { String childName = DOMUtil . getLocalName ( child ) ; if ( childName . equals ( ELT_COMPLEXTYPE ) ) { elementType = fComplexTypeTraverser . traverseLocal ( child , schemaDoc , grammar ) ; haveAnonType = true ; child = DOMUtil . getNextSiblingElement ( child ) ; } else if ( childName . equals ( ELT_SIMPLETYPE ) ) { elementType = fSimpleTypeTraverser . traverseLocal ( child , schemaDoc , grammar ) ; haveAnonType = true ; child = DOMUtil . getNextSiblingElement ( child ) ; } } if ( ( elementType == null ) && ( typeAtt != null ) ) { elementType = ( ( XSTypeDecl ) ( fSchemaHandler . getGlobalDecl ( schemaDoc , TYPEDECL_TYPE , typeAtt ) ) ) ; } if ( ( elementType == null ) && ( ( element . fSubGroup ) != null ) ) { elementType = element . fSubGroup . fType ; } if ( elementType == null ) { elementType = SchemaGrammar . fAnyType ; } element . fType = elementType ; if ( child != null ) { String childName = DOMUtil . getLocalName ( child ) ; while ( ( child != null ) && ( ( ( childName . equals ( ELT_KEY ) ) || ( childName . equals ( ELT_KEYREF ) ) ) || ( childName . equals ( ELT_UNIQUE ) ) ) ) { if ( ( childName . equals ( ELT_KEY ) ) || ( childName . equals ( ELT_UNIQUE ) ) ) { fUniqueOrKeyTraverser . traverse ( child , element , schemaDoc , grammar ) ; if ( ( DOMUtil . getAttrValue ( child , ATT_NAME ) . length ( ) ) != 0 ) { fSchemaHandler . checkForDuplicateNames ( ( ( schemaDoc . fTargetNamespace ) == null ? "," + ( DOMUtil . getAttrValue ( child , ATT_NAME ) ) : ( ( schemaDoc . fTargetNamespace ) + "," ) + ( DOMUtil . getAttrValue ( child , ATT_NAME ) ) ) , fSchemaHandler . getIDRegistry ( ) , child , schemaDoc ) ; } } else <START_BUG> if ( childName == ( SchemaSymbols . ELT_KEYREF ) ) { <END_BUG> fSchemaHandler . storeKeyRef ( child , schemaDoc , element ) ; } child = DOMUtil . getNextSiblingElement ( child ) ; if ( child != null ) { childName = DOMUtil . getLocalName ( child ) ; } } } if ( nameAtt != null ) grammar . addGlobalElementDecl ( element ) ; if ( nameAtt == null ) { if ( isGlobal ) reportSchemaError ( "s4s-att-must-appear" , new Object [ ] { NO_NAME , SchemaSymbols . ATT_NAME } ) ; else reportSchemaError ( "src-element.2.1" , null ) ; nameAtt = NO_NAME ; } if ( child != null ) { reportSchemaError ( "s4s-elt-must-match" , new Object [ ] { nameAtt , "(annotation?,<seq2seq4repair_space>(simpleType<seq2seq4repair_space>|<seq2seq4repair_space>complexType)?,<seq2seq4repair_space>(unique<seq2seq4repair_space>|<seq2seq4repair_space>key<seq2seq4repair_space>|<seq2seq4repair_space>keyref)*))" } ) ; } if ( ( defaultAtt != null ) && ( fixedAtt != null ) ) { reportSchemaError ( "src-element.1" , new Object [ ] { nameAtt } ) ; } if ( haveAnonType && ( typeAtt != null ) ) { reportSchemaError ( "src-element.3" , new Object [ ] { nameAtt } ) ; } checkNotationType ( nameAtt , elementType ) ; if ( ( element . fDefault ) != null ) { if ( ! ( checkDefaultValid ( element ) ) ) { reportSchemaError ( "e-props-correct.2" , new Object [ ] { nameAtt , element . fDefault } ) ; } }

Fix:
if ( childName . equals ( ELT_KEYREF ) ) {