diff --git a/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java b/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java index d5590c6e46..9ef0d39a1a 100644 --- a/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java +++ b/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java @@ -128,8 +128,7 @@ public T construct() { @SuppressWarnings("unchecked") // T is the same raw type as is requested @Override public T construct() { try { - Object[] args = null; - return (T) constructor.newInstance(args); + return (T) constructor.newInstance(); } catch (InstantiationException e) { // TODO: JsonParseException ? throw new RuntimeException("Failed to invoke " + constructor + " with no args", e); diff --git a/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java b/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java index fb8305dd62..a74de3025b 100644 --- a/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java +++ b/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java @@ -1,10 +1,9 @@ package com.google.gson.internal.reflect; +import com.google.gson.JsonIOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import com.google.gson.JsonIOException; - public class ReflectionHelper { private ReflectionHelper() { } @@ -12,10 +11,8 @@ private ReflectionHelper() { } * Tries making the field accessible, wrapping any thrown exception in a * {@link JsonIOException} with descriptive message. * - * @param field - * Field to make accessible - * @throws JsonIOException - * If making the field accessible fails + * @param field field to make accessible + * @throws JsonIOException if making the field accessible fails */ public static void makeAccessible(Field field) throws JsonIOException { try { @@ -44,17 +41,15 @@ private static String constructorToString(Constructor constructor) { stringBuilder.append(parameters[i].getSimpleName()); } - return stringBuilder.append(")").toString(); + return stringBuilder.append(')').toString(); } /** * Tries making the constructor accessible, returning an exception message * if this fails. * - * @param constructor - * Constructor to make accessible - * @return - * Exception message; {@code null} if successful, non-{@code null} if + * @param constructor constructor to make accessible + * @return exception message; {@code null} if successful, non-{@code null} if * unsuccessful */ public static String tryMakeAccessible(Constructor constructor) { @@ -63,7 +58,7 @@ public static String tryMakeAccessible(Constructor constructor) { return null; } catch (Exception exception) { return "Failed making constructor '" + constructorToString(constructor) + "' accessible; " - + "either change its visibility or write a custom InstanceCreator for its declaring type: " + + "either change its visibility or write a custom InstanceCreator or TypeAdapter for its declaring type: " // Include the message since it might contain more detailed information + exception.getMessage(); } diff --git a/gson/src/test/java/com/google/gson/functional/ReflectionAccessTest.java b/gson/src/test/java/com/google/gson/functional/ReflectionAccessTest.java index 58493c9e86..2e225ce489 100644 --- a/gson/src/test/java/com/google/gson/functional/ReflectionAccessTest.java +++ b/gson/src/test/java/com/google/gson/functional/ReflectionAccessTest.java @@ -4,12 +4,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.util.Collections; - -import org.junit.Test; - import com.google.gson.Gson; import com.google.gson.JsonIOException; +import java.util.Collections; +import org.junit.Test; public class ReflectionAccessTest { /** @@ -36,8 +34,8 @@ public void testSerializeInternalImplementationObject() { fail("Missing exception; test has to be run with `--illegal-access=deny`"); } catch (JsonIOException expected) { assertTrue(expected.getMessage().startsWith( - "Failed making constructor 'java.util.Collections$EmptyList#EmptyList()' accessible; " - + "either change its visibility or write a custom InstanceCreator for its declaring type" + "Failed making constructor 'java.util.Collections$EmptyList#EmptyList()' accessible; " + + "either change its visibility or write a custom InstanceCreator or TypeAdapter for its declaring type" )); } }