Skip to content

Commit

Permalink
Fix nullability errors in jsinterop.base
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 676863376
  • Loading branch information
kevinoconnor7 authored and copybara-github committed Sep 20, 2024
1 parent 305b038 commit 6586ded
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 2 additions & 0 deletions java/jsinterop/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ javadoc_library(
j2cl_library(
name = "base-j2cl",
srcs = [":processed_j2cl_srcs"] + glob(["*.js"]),
# Tested internally in google3
experimental_enable_jspecify_support_do_not_enable_without_jspecify_static_checking_or_you_might_cause_an_outage = True,
deps = [
"//third_party:jspecify_annotations-j2cl",
"@com_google_j2cl//:jsinterop-annotations-j2cl",
Expand Down
16 changes: 8 additions & 8 deletions java/jsinterop/base/InternalJsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static native Object delete(Object obj, String key) /*-{
}-*/;

// J2CL_ONLY @JsMethod(name="setIndexed")
public static native void set(Object obj, String key, Object value) /*-{
public static native void set(Object obj, String key, @Nullable Object value) /*-{
obj[key] = value;
}-*/;

Expand Down Expand Up @@ -92,38 +92,38 @@ public static native void forEach(Object obj, JsForEachCallbackFn cb) /*-{
}-*/;

// J2CL_ONLY @JsMethod(name="castToAny")
public static native boolean asBoolean(Object obj) /*-{
public static native boolean asBoolean(@Nullable Object obj) /*-{
return obj;
}-*/;

// J2CL_ONLY @JsMethod(name="castToAny")
public static native double asDouble(Object obj) /*-{
public static native double asDouble(@Nullable Object obj) /*-{
return obj;
}-*/;

// J2CL_ONLY @JsMethod(name="castToAny")
public static native int asInt(Object obj) /*-{
public static native int asInt(@Nullable Object obj) /*-{
return obj;
}-*/;

// J2CL_ONLY @JsMethod(name="castToAny")
public static native short asShort(Object obj) /*-{
public static native short asShort(@Nullable Object obj) /*-{
return obj;
}-*/;

// J2CL_ONLY @JsMethod(name="castToAny")
public static native char asChar(Object obj) /*-{
public static native char asChar(@Nullable Object obj) /*-{
return obj;
}-*/;

// J2CL_ONLY @JsMethod(name="castToAny")
public static native byte asByte(Object obj) /*-{
public static native byte asByte(@Nullable Object obj) /*-{
return obj;
}-*/;

@UnsafeNativeLong
// J2CL_ONLY @JsMethod(name="castToAny")
public static native long asLong(Object obj) /*-{
public static native long asLong(@Nullable Object obj) /*-{
return obj;
}-*/;

Expand Down
5 changes: 3 additions & 2 deletions java/jsinterop/base/InternalPreconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
*/
public final class InternalPreconditions {

private static final boolean IS_TYPE_CHECKED = getProperty("jsinterop.checks").equals("ENABLED");
private static final boolean IS_ASSERTED = getProperty("jre.checkedMode").equals("ENABLED");
private static final boolean IS_TYPE_CHECKED = getProperty("jsinterop.checks") == "ENABLED";

private static final boolean IS_ASSERTED = getProperty("jre.checkedMode") == "ENABLED";

public static void checkType(boolean expression) {
if (IS_TYPE_CHECKED) {
Expand Down
9 changes: 3 additions & 6 deletions java/jsinterop/base/Js.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ public static <T> JsConstructorFn<T> asConstructorFn(Class<T> clazz) {
}

/** Returns {@code JsPropertyMap} view of provided object. */
public static @Nullable JsPropertyMap<@Nullable Object> asPropertyMap(
@Nullable Object obj) {
public static @Nullable JsPropertyMap<@Nullable Object> asPropertyMap(@Nullable Object obj) {
return uncheckedCast(obj);
}

/** Returns {@code JsArrayLike} view of provided array-like object. */
public static @Nullable JsArrayLike<@Nullable Object> asArrayLike(
@Nullable Object obj) {
public static @Nullable JsArrayLike<@Nullable Object> asArrayLike(@Nullable Object obj) {
// TODO(goktug): switch to custom $isInstance
checkType(obj == null || InternalJsUtil.hasLength(obj));
return uncheckedCast(obj);
Expand Down Expand Up @@ -139,8 +137,7 @@ public static byte asByte(Object obj) {
* interface to a final Java class (like String).
*/
@SuppressWarnings({"TypeParameterUnusedInFormals", "unchecked"})
public static <T extends @Nullable Object> T cast(
@DoNotAutobox @Nullable Object obj) {
public static <T extends @Nullable Object> T cast(@DoNotAutobox @Nullable Object obj) {
return (T) obj;
}

Expand Down
2 changes: 1 addition & 1 deletion java/jsinterop/base/JsArrayLike.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ default void delete(int index) {
@JsOverlay
default List<T> asList() {
// Since it is hidden behind Arrays.asList, it is safe to do uncheckedCast.
T[] asArray = Js.uncheckedCast(this);
T[] asArray = Js.<T[]>uncheckedCast(this);
return Arrays.asList(asArray);
}
}

0 comments on commit 6586ded

Please sign in to comment.