import java.beans.IntrospectionException; 
import java.beans.PropertyDescriptor; 
import java.beans.SimpleBeanInfo; 
import java.beans.XMLEncoder; 
import java.io.ByteArrayOutputStream; 

public class XmlEncoderBugTest extends SimpleBeanInfo { 

    private static final int MAX_ITERATIONS = 100; 
    private static PropertyDescriptor[] propertyDescriptors; 

    static { 
        try { 
            propertyDescriptors = new PropertyDescriptor[]{ 
                    new PropertyDescriptor("booleanOne", XmlEncoderBugTest.class), 
                    new PropertyDescriptor("booleanTwo", XmlEncoderBugTest.class) 
            }; 
        } catch (IntrospectionException e) { 
            throw new RuntimeException(e); 
        } 
    } 

    private boolean booleanOne = true; 
    private boolean booleanTwo = false; 

    public boolean isBooleanOne() { 
        return booleanOne; 
    } 

    public void setBooleanOne(boolean booleanOne) { 
        this.booleanOne = booleanOne; 
    } 

    public boolean isBooleanTwo() { 
        return booleanTwo; 
    } 

    public void setBooleanTwo(boolean booleanTwo) { 
        this.booleanTwo = booleanTwo; 
    } 

    @Override 
    public PropertyDescriptor[] getPropertyDescriptors() { 
        return propertyDescriptors; 
    } 

    public static void main(String[] args) { 
        for (int i = 0; i < MAX_ITERATIONS; i++) { 
            ByteArrayOutputStream out = new ByteArrayOutputStream(); 
            XMLEncoder xmlEncoder = new XMLEncoder(out); 

            XmlEncoderBugTest object = new XmlEncoderBugTest(); 
            object.setBooleanTwo(true); 

            xmlEncoder.writeObject(object); 
            xmlEncoder.close(); 

            String encoded = new String(out.toByteArray()); 
            if (i == 0) { 
                System.out.println("Correct XML encoding:"); 
                System.out.println(encoded); 
            } else if (encoded.contains("Boolean0")) { 
                System.out.println("Wrong XML encoding in iteration " + i + ":"); 
                System.out.println(encoded); 
                return; 
            } 
        } 
        System.out.println("No error detected after " + MAX_ITERATIONS + " iterations."); 
    } 
} 