Skip to content

Commit 7de33b8

Browse files
committed
relation constructor should fail fast for null values to track down non-standard initialization (e.g. JSON libs)
1 parent 5aacd67 commit 7de33b8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

objectbox-java/src/main/java/io/objectbox/relation/ToMany.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public class ToMany<TARGET> implements List<TARGET>, Serializable {
7474
transient private boolean removeFromTargetBox;
7575

7676
public ToMany(Object sourceEntity, RelationInfo<TARGET> relationInfo) {
77+
if(sourceEntity == null ) {
78+
throw new IllegalArgumentException("No source entity given (null)");
79+
}
80+
if(relationInfo == null) {
81+
throw new IllegalArgumentException("No relation info given (null)");
82+
}
7783
this.entity = sourceEntity;
7884
this.relationInfo = relationInfo;
7985
}

objectbox-java/src/main/java/io/objectbox/relation/ToOne.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public class ToOne<TARGET> implements Serializable {
5555
* @param relationInfo Meta info as generated in the Entity_ (entity name plus underscore) classes.
5656
*/
5757
public ToOne(Object sourceEntity, RelationInfo relationInfo) {
58+
if(sourceEntity == null ) {
59+
throw new IllegalArgumentException("No source entity given (null)");
60+
}
61+
if(relationInfo == null) {
62+
throw new IllegalArgumentException("No relation info given (null)");
63+
}
5864
this.entity = sourceEntity;
5965
this.relationInfo = relationInfo;
6066
virtualProperty = relationInfo.targetIdProperty == null;

0 commit comments

Comments
 (0)