Buggy code:
else if ( trimDifferential ) derived . setExample ( null ) ; else derived . getExample ( ) . setUserData ( ProfileUtilities . DERIVATION_EQUALS , true ) ; } if ( derived . hasMaxLengthElement ( ) ) { if ( ! ( Base . compareDeep ( derived . getMaxLengthElement ( ) , base . getMaxLengthElement ( ) , false ) ) ) base . setMaxLengthElement ( derived . getMaxLengthElement ( ) . copy ( ) ) ; else if ( trimDifferential ) derived . setMaxLengthElement ( null ) ; else derived . getMaxLengthElement ( ) . setUserData ( ProfileUtilities . DERIVATION_EQUALS , true ) ; } if ( derived . hasMustSupportElement ( ) ) { if ( ! ( Base . compareDeep ( derived . getMustSupportElement ( ) , base . getMustSupportElement ( ) , false ) ) ) base . setMustSupportElement ( derived . getMustSupportElement ( ) . copy ( ) ) ; else if ( trimDifferential ) derived . setMustSupportElement ( null ) ; else derived . getMustSupportElement ( ) . setUserData ( ProfileUtilities . DERIVATION_EQUALS , true ) ; } if ( isExtension ) { if ( ! ( Base . compareDeep ( derived . getIsModifierElement ( ) , base . getIsModifierElement ( ) , false ) ) ) base . setIsModifierElement ( derived . getIsModifierElement ( ) . copy ( ) ) ; else if ( trimDifferential ) derived . setIsModifierElement ( null ) ; else derived . getIsModifierElement ( ) . setUserData ( ProfileUtilities . DERIVATION_EQUALS , true ) ; } if ( derived . hasBinding ( ) ) { if ( ! ( Base . compareDeep ( derived . getBinding ( ) , base . getBinding ( ) , false ) ) ) { if ( ( ( base . hasBinding ( ) ) && ( ( base . getBinding ( ) . getStrength ( ) ) == ( BindingStrength . REQUIRED ) ) ) && ( ( base . getBinding ( ) . getStrength ( ) ) != ( BindingStrength . REQUIRED ) ) ) throw new Exception ( ( ( ( ( ( ( ( "StructureDefinition<seq2seq4repair_space>" + pn ) + "<seq2seq4repair_space>at<seq2seq4repair_space>" ) + ( derived . getPath ( ) ) ) + ":<seq2seq4repair_space>illegal<seq2seq4repair_space>attempt<seq2seq4repair_space>to<seq2seq4repair_space>change<seq2seq4repair_space>a<seq2seq4repair_space>binding<seq2seq4repair_space>from<seq2seq4repair_space>" ) + ( base . getBinding ( ) . getStrength ( ) . toCode ( ) ) ) + "<seq2seq4repair_space>to<seq2seq4repair_space>" ) + ( base . getBinding ( ) . getStrength ( ) . toCode ( ) ) ) ) ; base . setBinding ( derived . getBinding ( ) . copy ( ) ) ; } else if ( trimDifferential ) derived . setBinding ( null ) ; else derived . getBinding ( ) . setUserData ( ProfileUtilities . DERIVATION_EQUALS , true ) ; } if ( derived . hasIsSummaryElement ( ) ) { if ( ! ( Base . compareDeep ( derived . getIsSummaryElement ( ) , base . getIsSummaryElement ( ) , false ) ) ) base . setIsSummaryElement ( derived . getIsSummaryElement ( ) . copy ( ) ) ; else if ( trimDifferential ) derived . setIsSummaryElement ( null ) ; else derived . getIsSummaryElement ( ) . setUserData ( ProfileUtilities . DERIVATION_EQUALS , true ) ; } if ( derived . hasType ( ) ) { if ( ! ( Base . compareDeep ( derived . getType ( ) , base . getType ( ) , false ) ) ) { if ( base . hasType ( ) ) { for ( TypeRefComponent ts : derived . getType ( ) ) { boolean ok = false ; CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder ( ) ; for ( TypeRefComponent td : base . getType ( ) ) { b . append ( td . getCode ( ) ) ; <START_BUG> if ( ( ( ( ( td . getCode ( ) . equals ( ts . getCode ( ) ) ) || ( td . getCode ( ) . equals ( "Extension" ) ) ) || ( td . getCode ( ) . equals ( "Element" ) ) ) || ( td . getCode ( ) . equals ( "*" ) ) ) || ( ( td . getCode ( ) . equals ( "Resource" ) ) && ( pkp . isResource ( ts . getCode ( ) ) ) ) ) <END_BUG> ok = true ; } if ( ! ok ) throw new Exception ( ( ( ( ( ( ( ( "StructureDefinition<seq2seq4repair_space>" + pn ) + "<seq2seq4repair_space>at<seq2seq4repair_space>" ) + ( derived . getPath ( ) ) ) + ":<seq2seq4repair_space>illegal<seq2seq4repair_space>constrained<seq2seq4repair_space>type<seq2seq4repair_space>" ) + ( ts . getCode ( ) ) ) + "<seq2seq4repair_space>from<seq2seq4repair_space>" ) + ( b . toString ( ) ) ) ) ; } } base . getType ( ) . clear ( ) ; for ( TypeRefComponent t : derived . getType ( ) ) base . getType ( ) . add ( t . copy ( ) ) ; } else if ( trimDifferential ) derived . getType ( ) . clear ( ) ; else for ( TypeRefComponent t : derived . getType ( ) ) t . setUserData ( ProfileUtilities . DERIVATION_EQUALS , true ) ; } if ( derived . hasMapping ( ) ) { if ( ! ( Base . compareDeep ( derived . getMapping ( ) , base . getMapping ( ) , false ) ) ) { for ( ElementDefinitionMappingComponent s : derived . getMapping ( ) ) { boolean found = false ; for ( ElementDefinitionMappingComponent d : base . getMapping ( ) ) { found = found || ( ( d . getIdentity ( ) . equals ( s . getIdentity ( ) ) ) && ( d . getMap ( ) . equals ( s . getMap ( ) ) ) ) ; }

Fix:
if ( ( ( ( ( td . getCode ( ) . equals ( ts . getCode ( ) ) ) || ( td . getCode ( ) . equals ( "Extension" ) ) ) || ( td . getCode ( ) . equals ( "Element" ) ) ) || ( td . getCode ( ) . equals ( "*" ) ) ) || ( ( td . getCode ( ) . equals ( "Resource" ) ) || ( ( td . getCode ( ) . equals ( "DomainResource" ) ) && ( pkp . isResource ( ts . getCode ( ) ) ) ) ) )