Skip to content

Commit 4a1bdce

Browse files
BoxStoreBuilder: prevent modification of model after init.
This is currently not really relevant as model is passed unchecked to the native side and not used for any other purpose. But it may be in the future, so rather be safe than sorry.
1 parent 1e93772 commit 4a1bdce

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.OutputStream;
2828
import java.lang.reflect.Method;
2929
import java.util.ArrayList;
30+
import java.util.Arrays;
3031
import java.util.List;
3132

3233
import javax.annotation.Nonnull;
@@ -107,10 +108,11 @@ private BoxStoreBuilder() {
107108
/** Called internally from the generated class "MyObjectBox". Check MyObjectBox.builder() to get an instance. */
108109
@Internal
109110
public BoxStoreBuilder(byte[] model) {
110-
this.model = model;
111111
if (model == null) {
112112
throw new IllegalArgumentException("Model may not be null");
113113
}
114+
// Future-proofing: copy to prevent external modification.
115+
this.model = Arrays.copyOf(model, model.length);
114116
}
115117

116118
/**

0 commit comments

Comments
 (0)