Buggy code:
class XSDComplexTypeTraverser extends XSDAbstractParticleTraverser { private static final int GLOBAL_NUM = 11 ; private static XSParticleDecl fErrorContent = null ; private static XSWildcardDecl fErrorWildcard = null ; private static XSParticleDecl getErrorContent ( ) { } private static XSWildcardDecl getErrorWildcard ( ) { } private String fName = null ; private String fTargetNamespace = null ; private short fDerivedBy = XSConstants . DERIVATION_RESTRICTION ; private short fFinal = XSConstants . DERIVATION_NONE ; private short fBlock = XSConstants . DERIVATION_NONE ; private short fContentType = XSComplexTypeDecl . CONTENTTYPE_EMPTY ; private XSTypeDefinition fBaseType = null ; private XSAttributeGroupDecl fAttrGrp = null ; private XSSimpleType fXSSimpleType = null ; private XSParticleDecl fParticle = null ; private boolean fIsAbstract = false ; private XSComplexTypeDecl fComplexTypeDecl = null ; private XSAnnotationImpl [ ] fAnnotations = null ; private Object [ ] fGlobalStore = null ; private int fGlobalStorePos = 0 ; XSDComplexTypeTraverser ( XSDHandler handler , XSAttributeChecker gAttrCheck ) { } private static final boolean DEBUG = false ; private static final class ComplexTypeRecoverableError extends Exception { private static final long serialVersionUID = 6802729912091130335L ; Object [ ] errorSubstText = null ; Element errorElem = null ; ComplexTypeRecoverableError ( ) { } ComplexTypeRecoverableError ( String msgKey , Object [ ] args , Element e ) { } } XSComplexTypeDecl traverseLocal ( Element complexTypeNode , XSDocumentInfo schemaDoc , SchemaGrammar grammar ) { } XSComplexTypeDecl traverseGlobal ( Element complexTypeNode , XSDocumentInfo schemaDoc , SchemaGrammar grammar ) { Object [ ] attrValues = fAttrChecker . checkAttributes ( complexTypeNode , true , schemaDoc ) ; String complexTypeName = ( ( String ) ( attrValues [ XSAttributeChecker . ATTIDX_NAME ] ) ) ; contentBackup ( ) ; XSComplexTypeDecl type = traverseComplexTypeDecl ( complexTypeNode , complexTypeName , attrValues , schemaDoc , grammar ) ; contentRestore ( ) ; grammar . addComplexTypeDecl ( type , fSchemaHandler . element2Locator ( complexTypeNode ) ) ; if ( complexTypeName == null ) { reportSchemaError ( "s4s-att-must-appear" , new Object [ ] { SchemaSymbols . ELT_COMPLEXTYPE , SchemaSymbols . ATT_NAME } , complexTypeNode ) ; type = null ; } else { if ( ( grammar . getGlobalTypeDecl ( type . getName ( ) ) ) == null ) { grammar . addGlobalComplexTypeDecl ( type ) ; } if ( fSchemaHandler . fTolerateDuplicates ) { final String loc = fSchemaHandler . schemaDocument2SystemId ( schemaDoc ) ; final XSTypeDefinition type2 = grammar . getGlobalTypeDecl ( type . getName ( ) , loc ) ; if ( type2 == null ) { grammar . addGlobalComplexTypeDecl ( type , loc ) ; } else { <START_BUG> if ( type instanceof XSComplexTypeDecl ) { <END_BUG> type = ( ( XSComplexTypeDecl ) ( type2 ) ) ; } } fSchemaHandler . addGlobalTypeDecl ( type ) ; } } fAttrChecker . returnAttrArray ( attrValues , schemaDoc ) ; return type ; } private XSComplexTypeDecl traverseComplexTypeDecl ( Element complexTypeDecl , String complexTypeName , Object [ ] attrValues , XSDocumentInfo schemaDoc , SchemaGrammar grammar ) { } private void traverseSimpleContent ( Element simpleContentElement , XSDocumentInfo schemaDoc , SchemaGrammar grammar ) throws XSDComplexTypeTraverser . ComplexTypeRecoverableError { } private void traverseComplexContent ( Element complexContentElement , boolean mixedOnType , XSDocumentInfo schemaDoc , SchemaGrammar grammar ) throws XSDComplexTypeTraverser . ComplexTypeRecoverableError { } private void mergeAttributes ( XSAttributeGroupDecl fromAttrGrp , XSAttributeGroupDecl toAttrGrp , String typeName , boolean extension , Element elem ) throws XSDComplexTypeTraverser . ComplexTypeRecoverableError { } private void processComplexContent ( Element complexContentChild , boolean isMixed , boolean isDerivation , XSDocumentInfo schemaDoc , SchemaGrammar grammar ) throws XSDComplexTypeTraverser . ComplexTypeRecoverableError { } private boolean isAttrOrAttrGroup ( Element e ) { } private void traverseSimpleContentDecl ( Element simpleContentDecl ) { } private void traverseComplexContentDecl ( Element complexContentDecl , boolean mixedOnComplexTypeDecl ) { } private String genAnonTypeName ( Element complexTypeDecl ) { } private void handleComplexTypeError ( String messageId , Object [ ] args , Element e ) { } private void contentBackup ( ) { } private void contentRestore ( ) { } private void addAnnotation ( XSAnnotationImpl annotation ) { } }

Fix:
if ( type2 instanceof XSComplexTypeDecl ) {