Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail gracefully when a primitive value is absent. #1445

Merged
merged 1 commit into from Dec 5, 2021

Commits on Dec 4, 2021

  1. Fail gracefully when a primitive value is absent.

    Without this we get an AssertionError, which is the wrong exception
    type for a JSON schema mismatch:
    
        java.lang.AssertionError: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
          at com.squareup.moshi.RecordJsonAdapter.fromJson(RecordJsonAdapter.java:168)
          at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(NullSafeJsonAdapter.java:41)
          at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:70)
          at com.squareup.moshi.records.RecordsTest.absentPrimitiveFails(RecordsTest.java:257)
        Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
          at java.base/sun.invoke.util.ValueConversions.unboxInteger(ValueConversions.java:81)
          at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
          at com.squareup.moshi.RecordJsonAdapter.fromJson(RecordJsonAdapter.java:156)
          ... 46 more
    swankjesse committed Dec 4, 2021
    Configuration menu
    Copy the full SHA
    fe9a303 View commit details
    Browse the repository at this point in the history