ArrayIndexOutOfBoundsException when model object add a new field

94 views
Skip to first unread message

xc s

unread,
May 19, 2020, 9:39:47 AM5/19/20
to Ebean ORM
Hello,

I run two spring application: app1 & app2, model object cached share in redis. 
Then I add a new field to model object and upgrade app2 and fresh model object cache.

Now I load model object in app1, will throw ArrayIndexOutOfBoundsException, like this:

java.lang.ArrayIndexOutOfBoundsException: 22
at io.ebean.bean.EntityBeanIntercept.isLoadedProperty(EntityBeanIntercept.java:547)
at io.ebean.bean.EntityBeanIntercept.preGetter(EntityBeanIntercept.java:938)

How to avoid this issue? I think may be return null if  index is over the array.

My ebean version is 12.1.8.

Thanks

Xc

Rob Bygrave

unread,
May 20, 2020, 4:51:07 AM5/20/20
to ebean@googlegroups
You might want to create a test case?

--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/a8b6130d-f203-4f5c-a438-266d2e25556f%40googlegroups.com.

xc s

unread,
May 21, 2020, 8:50:49 AM5/21/20
to Ebean ORM
Thanks for your reply.

I use fast-serialization mock all case, save model object to file, then read it deserialization as object.

Step 1  Write

1.1 Model

@Entity
public class TestModel {
    public static Finder<Integer, TestModel> finder = new Finder<>(TestModel.class);
    @Id
    Integer id;
    String field1;
    ...
}

1.2 Write object to file

FSTConfiguration fst = FSTConfiguration.createDefaultConfiguration(); 
Path target = Paths.get("model_v1.log");
TestModel model = TestModel.finder.byId(id);
byte[] bb = fst.asByteArray(model);
Files.write(target, bb); 


Step 2 Read

2.1 Then add a field to model

@Entity
public class TestModel {
    public static Finder<Integer, TestModel> finder = new Finder<>(TestModel.class, ChargeToolApplication.DB_NAME);
    @Id
    Integer id;
    String field1;
    @org.nustaq.serialization.annotations.Version(1)
    String field2;
    ...
}

2.2 Read old data 

FSTConfiguration fst = FSTConfiguration.createDefaultConfiguration();
Path target = Paths.get("model_v1.log");
byte[] bb = Files.readAllBytes(target);
TestModel model = (TestModel) fst.asObject(bb);
System.out.println(model.getField1());
System.out.println(model.getField2()); // --> it will throw Exception

Exception stack

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2

at io.ebean.bean.EntityBeanIntercept.isLoadedProperty(EntityBeanIntercept.java:547)
at io.ebean.bean.EntityBeanIntercept.preGetter(EntityBeanIntercept.java:938)
at soda.charge.tool.vm.TestModel._ebean_get_field2(TestModel.java:6)
at soda.charge.tool.vm.TestModel.getField2(TestModel.java:41) 
 
I can't simple upgrade a online application for this exception, so maybe cache a ebean model is not good choose?  or maybe get a null value for model.getFields2().  

在 2020年5月20日星期三 UTC+8下午4:51:07,Rob Bygrave写道:
You might want to create a test case?

On Wed, 20 May 2020 at 01:39, xc s <pep...@gmail.com> wrote:
Hello,

I run two spring application: app1 & app2, model object cached share in redis. 
Then I add a new field to model object and upgrade app2 and fresh model object cache.

Now I load model object in app1, will throw ArrayIndexOutOfBoundsException, like this:

java.lang.ArrayIndexOutOfBoundsException: 22
at io.ebean.bean.EntityBeanIntercept.isLoadedProperty(EntityBeanIntercept.java:547)
at io.ebean.bean.EntityBeanIntercept.preGetter(EntityBeanIntercept.java:938)

How to avoid this issue? I think may be return null if  index is over the array.

My ebean version is 12.1.8.

Thanks

Xc

--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eb...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages