Buggy code:
protected boolean isMetaDataMode ( ) { } protected boolean isQueryMode ( ) { } protected boolean isMappingMode ( ) { } protected boolean isMappingMode ( ClassMetaData meta ) { } protected boolean isMappingMode ( ValueMetaData vmd ) { } public void addMetaData ( ClassMetaData meta ) { } public void addSequenceMetaData ( SequenceMetaData meta ) { } public void addQueryMetaData ( QueryMetaData meta ) { } public void addAll ( MetaDataRepository repos ) { } public boolean removeMetaData ( ClassMetaData meta ) { } public boolean removeSequenceMetaData ( SequenceMetaData meta ) { } public boolean removeQueryMetaData ( QueryMetaData meta ) { } public boolean removeAll ( MetaDataRepository repos ) { } public void clear ( ) { } protected void addSystemMappingElements ( Collection toSerialize ) { } private void serializationSort ( List objs ) { } protected AnnotationPersistenceMetaDataSerializer . SerializationComparator newSerializationComparator ( ) { } private void addSequenceMetaDatas ( Collection all ) { } private void addQueryMetaDatas ( Collection all ) { } protected AnnotationBuilder newAnnotationBuilder ( Class < ? extends Annotation > annType ) { } protected void addAnnotation ( AnnotationBuilder ab , Object meta ) { } protected void addAnnotation ( AnnotationBuilder ab , ClassMetaData meta ) { } protected void addAnnotation ( AnnotationBuilder ab , FieldMetaData meta ) { } protected void addAnnotation ( AnnotationBuilder ab , SequenceMetaData meta ) { } protected void addAnnotation ( AnnotationBuilder ab , QueryMetaData meta ) { } protected AnnotationBuilder addAnnotation ( Class < ? extends Annotation > annType , ClassMetaData meta ) { } protected AnnotationBuilder addAnnotation ( Class < ? extends Annotation > annType , FieldMetaData meta ) { } protected AnnotationBuilder addAnnotation ( Class < ? extends Annotation > annType , SequenceMetaData meta ) { } protected AnnotationBuilder addAnnotation ( Class < ? extends Annotation > annType , QueryMetaData meta ) { } protected void serialize ( Collection objects ) { } protected int type ( Object o ) { } protected void serializeSystemMappingElement ( Object obj ) { } private void serializeQuery ( QueryMetaData meta ) { } private void serializeQueryHints ( QueryMetaData meta , AnnotationBuilder ab ) { } protected void serializeSequence ( SequenceMetaData meta ) { } protected void serializeClass ( ClassMetaData meta ) { } private static Class < ? extends Annotation > getEntityAnnotationType ( ClassMetaData meta ) { } private static Class < ? extends Annotation > getFieldAnnotationType ( FieldMetaData fmd , PersistenceStrategy strat ) { } private static MetaDataTag getEntityTag ( ClassMetaData meta ) { } protected void addClassMappingAnnotations ( ClassMetaData mapping ) { } private void serializeIdClass ( ClassMetaData meta ) { } protected void serializeClassMappingContent ( ClassMetaData mapping ) { } protected void serializeInheritanceContent ( ClassMetaData mapping ) { } protected void serializeQueryMappings ( ClassMetaData meta ) { } private void serializeField ( FieldMetaData fmd , FieldMetaData orig ) { } protected void addFieldMappingAttributes ( FieldMetaData fmd , FieldMetaData orig , AnnotationBuilder ab ) { } protected boolean serializeAttributeOverride ( FieldMetaData fmd , FieldMetaData orig ) { } private void serializeAttributeOverrideContent ( FieldMetaData fmd , FieldMetaData orig ) { } protected void serializeAttributeOverrideMappingContent ( FieldMetaData fmd , FieldMetaData orig , AnnotationBuilder ab ) { } private void serializeCascades ( ValueMetaData vmd , AnnotationBuilder ab ) { EnumSet < CascadeType > cascades = EnumSet . noneOf ( CascadeType . class ) ; if ( ( vmd . getCascadePersist ( ) ) == ( ValueMetaData . CASCADE_IMMEDIATE ) ) { cascades . add ( PERSIST ) ; } if ( ( vmd . getCascadeAttach ( ) ) == ( ValueMetaData . CASCADE_IMMEDIATE ) ) { cascades . add ( MERGE ) ; } if ( ( vmd . getCascadeDelete ( ) ) == ( ValueMetaData . CASCADE_IMMEDIATE ) ) { cascades . add ( REMOVE ) ; } if ( ( vmd . getCascadeRefresh ( ) ) == ( ValueMetaData . CASCADE_IMMEDIATE ) ) { cascades . add ( REFRESH ) ; } if ( ( vmd . getCascadeDetach ( ) ) == ( ValueMetaData . CASCADE_IMMEDIATE ) ) { <START_BUG> cascades . add ( CLEAR ) ; <END_BUG> } if ( ( cascades . size ( ) ) == 5 ) { cascades . clear ( ) ; cascades . add ( ALL ) ; } if ( ! ( cascades . isEmpty ( ) ) ) { ab . add ( "cascade" , cascades ) ; } } protected PersistenceStrategy getStrategy ( FieldMetaData fmd ) { } private void addBasicAttributes ( FieldMetaData fmd , AnnotationBuilder ab ) { } private void addManyToOneAttributes ( FieldMetaData fmd , AnnotationBuilder ab ) { } private void addOneToOneAttributes ( FieldMetaData fmd , AnnotationBuilder ab ) { } private void addOneToManyAttributes ( FieldMetaData fmd , AnnotationBuilder ab ) { } private void addManyToManyAttributes ( FieldMetaData fmd , AnnotationBuilder ab ) { } private void addTargetEntityAttribute ( FieldMetaData fmd , AnnotationBuilder ab ) { } protected void serializeFieldMappingContent ( FieldMetaData fmd , PersistenceStrategy strategy , AnnotationBuilder ab ) { } protected void addStrategyMappingAttributes ( FieldMetaData fmd , AnnotationBuilder ab ) { } protected Collection getObjects ( ) { } protected void writeAnnotations ( Object meta , List < AnnotationBuilder > builders , Map output ) { } public void serialize ( Map output , int flags ) throws IOException { } public void serialize ( File file , int flags ) throws IOException { } public void serialize ( Writer out , int flags ) throws IOException { } public void serialize ( int flags ) throws IOException { } private static class ClassSeqs implements Comparable < AnnotationPersistenceMetaDataSerializer . ClassSeqs > , Comparator < SequenceMetaData > , SourceTracker { private final SequenceMetaData [ ] _seqs ; public ClassSeqs ( List < SequenceMetaData > seqs ) { } public SequenceMetaData [ ] getSequences ( ) { } public int compare ( SequenceMetaData o1 , SequenceMetaData o2 ) { } public File getSourceFile ( ) { } public Object getSourceScope ( ) { } public int getSourceType ( ) { }

Fix:
cascades . add ( DETACH ) ;