Menu

#29 Bug in processing enums

open
nobody
None
5
2011-12-17
2011-12-17
Anonymous
No

I've found the bug in the logic of handling enums: in the method org.simpleframework.xml.transform.PackageMatcher#matchEnum this is not sufficient to check if class is enum, also check of the parent class is needed. Here is the example of failing test:
@Test
public void testFoo() throws Exception {
final Serializer serializer = new Persister();
final FooObject fooObject = new FooObject();
fooObject.setFoo(Foo.NAY);
serializer.write(fooObject, new StringWriter());
}

@Root
public static class FooObject {

@Element
private Foo foo;

public FooObject() {
}

public Foo getFoo() {
return foo;
}

public void setFoo(Foo foo) {
this.foo = foo;
}
}

public static enum Foo {
YEA {
public boolean foo() {
return true;
}
},
NAY {
public boolean foo() {
return false;
}
};

public abstract boolean foo();
}

The problem is in the abstract method in the enum.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB
Gen AI apps are built with MongoDB Atlas
Atlas offers built-in vector search and global availability across 125+ regions. Start building AI apps faster, all in one place.