@@ -80,9 +80,9 @@ void passUncaughtExceptionToJs(Throwable ex, String stackTrace) {
80
80
"Primitive types need to be manually wrapped in their respective Object wrappers.\n " +
81
81
"If you are creating an instance of an inner class, make sure to always provide reference to the outer `this` as the first argument." ;
82
82
83
- private final SparseArray < Object > strongInstances = new SparseArray < Object >();
83
+ private final HashMap < Integer , Object > strongInstances = new HashMap < >();
84
84
85
- private final SparseArray < WeakReference <Object >> weakInstances = new SparseArray < WeakReference < Object > >();
85
+ private final HashMap < Integer , WeakReference <Object >> weakInstances = new HashMap < >();
86
86
87
87
private final NativeScriptHashMap <Object , Integer > strongJavaObjectToID = new NativeScriptHashMap <Object , Integer >();
88
88
@@ -801,7 +801,7 @@ private void makeInstanceWeak(int javaObjectID, boolean keepAsWeak) {
801
801
weakInstances .put (javaObjectID , new WeakReference <Object >(instance ));
802
802
}
803
803
804
- strongInstances .delete (javaObjectID );
804
+ strongInstances .remove (javaObjectID );
805
805
strongJavaObjectToID .remove (instance );
806
806
}
807
807
@@ -829,17 +829,17 @@ private boolean makeInstanceWeakAndCheckIfAlive(int javaObjectID) {
829
829
if (instance == null ) {
830
830
// The Java was moved from strong to weak, and then the Java instance was collected.
831
831
weakInstances .remove (javaObjectID );
832
- weakJavaObjectToID .remove (Integer . valueOf ( javaObjectID ) );
832
+ weakJavaObjectToID .remove (javaObjectID );
833
833
return false ;
834
834
} else {
835
835
return true ;
836
836
}
837
837
}
838
838
} else {
839
- strongInstances .delete (javaObjectID );
839
+ strongInstances .remove (javaObjectID );
840
840
strongJavaObjectToID .remove (instance );
841
841
842
- weakJavaObjectToID .put (instance , Integer . valueOf ( javaObjectID ) );
842
+ weakJavaObjectToID .put (instance , javaObjectID );
843
843
weakInstances .put (javaObjectID , new WeakReference <Object >(instance ));
844
844
845
845
return true ;
@@ -862,7 +862,7 @@ private void checkWeakObjectAreAlive(ByteBuffer input, ByteBuffer output, int le
862
862
863
863
if (instance == null ) {
864
864
isReleased = 1 ;
865
- weakInstances .delete (javaObjectId );
865
+ weakInstances .remove (javaObjectId );
866
866
} else {
867
867
isReleased = 0 ;
868
868
}
@@ -880,7 +880,11 @@ private Object getJavaObjectByID(int javaObjectID) throws Exception {
880
880
logger .write ("Platform.getJavaObjectByID:" + javaObjectID );
881
881
}
882
882
883
- Object instance = strongInstances .get (javaObjectID , keyNotFoundObject );
883
+ Object instance = strongInstances .get (javaObjectID );
884
+
885
+ if (instance == null ) {
886
+ instance = keyNotFoundObject ;
887
+ }
884
888
885
889
if (instance == keyNotFoundObject ) {
886
890
WeakReference <Object > wr = weakInstances .get (javaObjectID );
0 commit comments