Buggy code:
XSTypeDefinition fCurrentType ; XSTypeDefinition [ ] fTypeStack = new XSTypeDefinition [ XMLSchemaValidator . INITIAL_STACK_SIZE ] ; XSCMValidator fCurrentCM ; XSCMValidator [ ] fCMStack = new XSCMValidator [ XMLSchemaValidator . INITIAL_STACK_SIZE ] ; int [ ] fCurrCMState ; int [ ] [ ] fCMStateStack = new int [ XMLSchemaValidator . INITIAL_STACK_SIZE ] [ ] ; boolean fStrictAssess = true ; boolean [ ] fStrictAssessStack = new boolean [ XMLSchemaValidator . INITIAL_STACK_SIZE ] ; final StringBuffer fBuffer = new StringBuffer ( ) ; boolean fAppendBuffer = true ; boolean fSawText = false ; boolean [ ] fSawTextStack = new boolean [ XMLSchemaValidator . INITIAL_STACK_SIZE ] ; boolean fSawCharacters = false ; boolean [ ] fStringContent = new boolean [ XMLSchemaValidator . INITIAL_STACK_SIZE ] ; boolean fSawChildren = false ; boolean [ ] fSawChildrenStack = new boolean [ XMLSchemaValidator . INITIAL_STACK_SIZE ] ; final QName fTempQName = new QName ( ) ; ValidatedInfo fValidatedInfo = new ValidatedInfo ( ) ; private ValidationState fState4XsiType = new ValidationState ( ) ; private ValidationState fState4ApplyDefault = new ValidationState ( ) ; protected XMLSchemaValidator . XPathMatcherStack fMatcherStack = new XMLSchemaValidator . XPathMatcherStack ( ) ; protected XMLSchemaValidator . ValueStoreCache fValueStoreCache = new XMLSchemaValidator . ValueStoreCache ( ) ; public XMLSchemaValidator ( ) { } public void reset ( XMLComponentManager componentManager ) throws XMLConfigurationException { } public void startValueScopeFor ( IdentityConstraint identityConstraint , int initialDepth ) { } public XPathMatcher activateField ( Field field , int initialDepth ) { } public void endValueScopeFor ( IdentityConstraint identityConstraint , int initialDepth ) { } private void activateSelectorFor ( IdentityConstraint ic ) { } void ensureStackCapacity ( ) { } void handleStartDocument ( XMLLocator locator , String encoding ) { } void handleEndDocument ( ) { } XMLString handleCharacters ( XMLString text ) { } private void normalizeWhitespace ( XMLString value , boolean collapse ) { } private void normalizeWhitespace ( String value , boolean collapse ) { } void handleIgnorableWhitespace ( XMLString text ) { } Augmentations handleStartElement ( QName element , XMLAttributes attributes , Augmentations augs ) { } Augmentations handleEndElement ( QName element , Augmentations augs ) { if ( XMLSchemaValidator . DEBUG ) { System . out . println ( ( "==>handleEndElement:" + element ) ) ; } if ( ( fSkipValidationDepth ) >= 0 ) { if ( ( ( fSkipValidationDepth ) == ( fElementDepth ) ) && ( ( fSkipValidationDepth ) > 0 ) ) { fNFullValidationDepth = ( fSkipValidationDepth ) - 1 ; fSkipValidationDepth = - 1 ; ( fElementDepth ) -- ; fSubElement = fSubElementStack [ fElementDepth ] ; fCurrentElemDecl = fElemDeclStack [ fElementDepth ] ; fNil = fNilStack [ fElementDepth ] ; fNotation = fNotationStack [ fElementDepth ] ; fCurrentType = fTypeStack [ fElementDepth ] ; fCurrentCM = fCMStack [ fElementDepth ] ; fStrictAssess = fStrictAssessStack [ fElementDepth ] ; fCurrCMState = fCMStateStack [ fElementDepth ] ; fSawText = fSawTextStack [ fElementDepth ] ; fSawCharacters = fStringContent [ fElementDepth ] ; fSawChildren = fSawChildrenStack [ fElementDepth ] ; } else { ( fElementDepth ) -- ; } if ( ( ( fElementDepth ) == ( - 1 ) ) && ( fFullChecking ) ) { XSConstraints . fullSchemaChecking ( fGrammarBucket , fSubGroupHandler , fCMBuilder , fXSIErrorReporter . fErrorReporter ) ; } if ( fAugPSVI ) augs = getEmptyAugs ( augs ) ; return augs ; } processElementContent ( element ) ; int oldCount = fMatcherStack . getMatcherCount ( ) ; for ( int i = oldCount - 1 ; i >= 0 ; i -- ) { XPathMatcher matcher = fMatcherStack . getMatcherAt ( i ) ; if ( ( fCurrentElemDecl ) == null ) matcher . endElement ( element , null , false , fValidatedInfo . actualValue ) ; else <START_BUG> matcher . endElement ( element , fCurrentElemDecl . fType , fCurrentElemDecl . getNillable ( ) , ( ( fDefaultValue ) == null ? fValidatedInfo . actualValue : fCurrentElemDecl . fDefault . actualValue ) ) ; <END_BUG> } if ( ( fMatcherStack . size ( ) ) > 0 ) { fMatcherStack . popContext ( ) ; } int newCount = fMatcherStack . getMatcherCount ( ) ; for ( int i = oldCount - 1 ; i >= newCount ; i -- ) { XPathMatcher matcher = fMatcherStack . getMatcherAt ( i ) ; if ( matcher instanceof Selector . Matcher ) { Selector . Matcher selMatcher = ( ( Selector . Matcher ) ( matcher ) ) ; IdentityConstraint id ; if ( ( ( id = selMatcher . getIdentityConstraint ( ) ) != null ) && ( ( id . getCategory ( ) ) != ( IdentityConstraint . IC_KEYREF ) ) ) { fValueStoreCache . transplant ( id , selMatcher . getInitialDepth ( ) ) ; } } } for ( int i = oldCount - 1 ; i >= newCount ; i -- ) { XPathMatcher matcher = fMatcherStack . getMatcherAt ( i ) ; if ( matcher instanceof Selector . Matcher ) { Selector . Matcher selMatcher = ( ( Selector . Matcher ) ( matcher ) ) ; IdentityConstraint id ; if ( ( ( id = selMatcher . getIdentityConstraint ( ) ) != null ) && ( ( id . getCategory ( ) ) == ( IdentityConstraint . IC_KEYREF ) ) ) { XMLSchemaValidator . ValueStoreBase values = fValueStoreCache . getValueStoreFor ( id , selMatcher . getInitialDepth ( ) ) ; if ( values != null ) values . endDocumentFragment ( ) ; } } } fValueStoreCache . endElement ( ) ; SchemaGrammar [ ] grammars = null ; if ( ( fElementDepth ) == 0 ) { String invIdRef = fValidationState . checkIDRefID ( ) ; fValidationState . resetIDTables ( ) ; if ( invIdRef != null ) { reportSchemaError ( "cvc-id.1" , new Object [ ] { invIdRef } ) ; } if ( fFullChecking ) { XSConstraints . fullSchemaChecking ( fGrammarBucket , fSubGroupHandler , fCMBuilder , fXSIErrorReporter . fErrorReporter ) ; } grammars = fGrammarBucket . getGrammars ( ) ;

Fix:
matcher . endElement ( element , fCurrentType , fCurrentElemDecl . getNillable ( ) , ( ( fDefaultValue ) == null ? fValidatedInfo . actualValue : fCurrentElemDecl . fDefault . actualValue ) ) ;