Skip to content

Commit ffbb2de

Browse files
committed
For #220, explicitly allow OneToMany to be set via constructor
With 220 the ebean-agent is now conservative and only allows certain initialisation for OneToMany. This fixes the 220 change to allow OneToMany to be set via constructor. [PUTFIELD on a OneToMany was proceeded by an ALOAD]
1 parent 74969f4 commit ffbb2de

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

ebean-agent/src/main/java/io/ebean/enhance/entity/ConstructorDeferredCode.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ boolean deferVisitVarInsn(int opcode, int var) {
7979
state = State.ALOAD;
8080
return true;
8181
}
82+
if (opcode == ALOAD) {
83+
// maybe constructor initialisation of OneToMany
84+
state = State.ALOAD;
85+
}
8286
return false;
8387
}
8488

@@ -225,6 +229,10 @@ boolean consumeVisitFieldInsn(int opcode, String owner, String name, String desc
225229
* Return true when a OneToMany or ManyToMany is not initialised in a supported manor.
226230
*/
227231
private boolean unsupportedInitialisation() {
232+
if (state == State.ALOAD) {
233+
// allow constructor initialisation of a OneToMany
234+
return false;
235+
}
228236
return state == State.MAYBE_UNSUPPORTED
229237
|| state == State.UNSET // proceeded by GETSTATIC field bytecode like Collections.EMPTY_LIST
230238
|| state == State.INVOKE_SPECIAL && !isConsumeManyType(); // e.g. new BeanList()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package test.model;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.Id;
6+
import jakarta.persistence.OneToMany;
7+
8+
import java.util.List;
9+
import java.util.UUID;
10+
11+
@Entity
12+
public class ReferencingBean {
13+
14+
@Id @GeneratedValue
15+
UUID id;
16+
17+
@OneToMany
18+
private List<PBean> rootBeans;
19+
20+
public ReferencingBean(List<PBean> rootBeans) {
21+
this.rootBeans = rootBeans;
22+
}
23+
24+
public List<PBean> getRootBeans() {
25+
return rootBeans;
26+
}
27+
28+
}

0 commit comments

Comments
 (0)