Skip to content

Commit

Permalink
[J2KT] Fix nullability in Collections readable.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 698759882
  • Loading branch information
Googler authored and copybara-github committed Nov 21, 2024
1 parent 104c290 commit d0e9c47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void testMap_specialized(MapOfString map) {
public static class CustomCollection<T extends @Nullable Object> extends AbstractCollection<T> {
@Override
public Iterator<T> iterator() {
return null;
throw new RuntimeException();
}

@Override
Expand Down Expand Up @@ -203,7 +203,7 @@ public boolean retainAll(Collection<?> c) {
public static class CustomList<T extends @Nullable Object> extends AbstractList<T> {
@Override
public T get(int index) {
return null;
throw new IndexOutOfBoundsException();
}

@Override
Expand Down Expand Up @@ -250,7 +250,7 @@ public boolean containsValue(@Nullable Object value) {
}

@Override
public V remove(@Nullable Object key) {
public @Nullable V remove(@Nullable Object key) {
key = convert(key);
return super.remove(key);
}
Expand All @@ -263,7 +263,7 @@ public boolean remove(@Nullable Object key, @Nullable Object value) {
}

@Override
public V get(@Nullable Object key) {
public @Nullable V get(@Nullable Object key) {
key = convert(key);
return super.get(key);
}
Expand Down Expand Up @@ -319,7 +319,7 @@ public boolean containsValue(@Nullable Object value) {
}

@Override
public String remove(@Nullable Object key) {
public @Nullable String remove(@Nullable Object key) {
key = convert(key);
return super.remove(key);
}
Expand All @@ -332,7 +332,7 @@ public boolean remove(@Nullable Object key, @Nullable Object value) {
}

@Override
public String get(@Nullable Object key) {
public @Nullable String get(@Nullable Object key) {
key = convert(key);
return super.get(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package j2kt

import javaemul.lang.*
import java.lang.IndexOutOfBoundsException
import java.lang.RuntimeException
import javaemul.lang.JavaAbstractCollection
import javaemul.lang.JavaAbstractList
Expand Down Expand Up @@ -252,7 +253,7 @@ open class Collections {
@ObjCName("J2ktJ2ktCollections_CustomCollection", exact = true)
open class CustomCollection<T>: JavaAbstractCollection<T>() {
override fun iterator(): MutableIterator<T> {
return null!!
throw RuntimeException()
}

override val size: Int
Expand Down Expand Up @@ -300,7 +301,7 @@ open class Collections {
@ObjCName("J2ktJ2ktCollections_CustomList", exact = true)
open class CustomList<T>: JavaAbstractList<T>() {
override fun get(index: Int): T {
return null as T
throw IndexOutOfBoundsException()
}

override val size: Int
Expand Down Expand Up @@ -346,10 +347,10 @@ open class Collections {
return super<JavaAbstractMap>.containsValue(value_1 as V)
}

override fun remove(key: K): V {
override fun remove(key: K): V? {
var key_1: Any? = key
key_1 = Collections.convert<Any?>(key_1)
return super<JavaAbstractMap>.remove(key_1 as K) as V
return super<JavaAbstractMap>.remove(key_1 as K)
}

override fun java_remove(key: Any?, value: Any?): Boolean {
Expand All @@ -360,10 +361,10 @@ open class Collections {
return super<JavaAbstractMap>.java_remove(key_1, value_1)
}

override fun get(key: K): V {
override fun get(key: K): V? {
var key_1: Any? = key
key_1 = Collections.convert<Any?>(key_1)
return super<JavaAbstractMap>.get(key_1 as K) as V
return super<JavaAbstractMap>.get(key_1 as K)
}

override fun java_getOrDefault(key: Any?, defaultValue: V?): V? {
Expand Down Expand Up @@ -425,7 +426,7 @@ open class Collections {
return super<Collections.CustomMap>.containsValue(value_1 as String)
}

override fun remove(key: String): String {
override fun remove(key: String): String? {
var key_1: Any? = key
key_1 = Collections.convert<Any?>(key_1)
return super<Collections.CustomMap>.remove(key_1 as String)
Expand All @@ -439,7 +440,7 @@ open class Collections {
return super<Collections.CustomMap>.java_remove(key_1, value_1)
}

override fun get(key: String): String {
override fun get(key: String): String? {
var key_1: Any? = key
key_1 = Collections.convert<Any?>(key_1)
return super<Collections.CustomMap>.get(key_1 as String)
Expand Down

0 comments on commit d0e9c47

Please sign in to comment.