Skip to content
Snippets Groups Projects
Commit ac838b88 authored by Mamadu-lamarana Bah's avatar Mamadu-lamarana Bah :speech_balloon:
Browse files

updt

parent 817bf11d
No related branches found
No related tags found
No related merge requests found
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" /> <mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/gson" vcs="Git" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -380,7 +380,8 @@ public final class JsonTreeReader extends JsonReader { ...@@ -380,7 +380,8 @@ public final class JsonTreeReader extends JsonReader {
return getPath(true); return getPath(true);
} }
private String locationString() { @Override
protected String locationString() {
return " at path " + getPath(); return " at path " + getPath();
} }
} }
/* /*
* Copyright (C) 2021 Google Inc. * Copyright (C) 2021 Google Inc.
* *
...@@ -48,9 +49,9 @@ public class ReflectionHelper { ...@@ -48,9 +49,9 @@ public class ReflectionHelper {
if (e.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) { if (e.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
String message = e.getMessage(); String message = e.getMessage();
String troubleshootingId = String troubleshootingId =
message != null && message.contains("to module com.google.gson") message != null && message.contains("to module com.google.gson")
? "reflection-inaccessible-to-module-gson" ? "reflection-inaccessible-to-module-gson"
: "reflection-inaccessible"; : "reflection-inaccessible";
return "\nSee " + TroubleshootingGuide.createUrl(troubleshootingId); return "\nSee " + TroubleshootingGuide.createUrl(troubleshootingId);
} }
return ""; return "";
...@@ -69,12 +70,12 @@ public class ReflectionHelper { ...@@ -69,12 +70,12 @@ public class ReflectionHelper {
} catch (Exception exception) { } catch (Exception exception) {
String description = getAccessibleObjectDescription(object, false); String description = getAccessibleObjectDescription(object, false);
throw new JsonIOException( throw new JsonIOException(
"Failed making " "Failed making "
+ description + description
+ " accessible; either increase its visibility" + " accessible; either increase its visibility"
+ " or write a custom TypeAdapter for its declaring type." + " or write a custom TypeAdapter for its declaring type."
+ getInaccessibleTroubleshootingSuffix(exception), + getInaccessibleTroubleshootingSuffix(exception),
exception); exception);
} }
} }
...@@ -87,7 +88,7 @@ public class ReflectionHelper { ...@@ -87,7 +88,7 @@ public class ReflectionHelper {
* @param uppercaseFirstLetter whether the first letter of the description should be uppercased * @param uppercaseFirstLetter whether the first letter of the description should be uppercased
*/ */
public static String getAccessibleObjectDescription( public static String getAccessibleObjectDescription(
AccessibleObject object, boolean uppercaseFirstLetter) { AccessibleObject object, boolean uppercaseFirstLetter) {
String description; String description;
if (object instanceof Field) { if (object instanceof Field) {
...@@ -130,13 +131,13 @@ public class ReflectionHelper { ...@@ -130,13 +131,13 @@ public class ReflectionHelper {
// Ideally parameter type would be java.lang.reflect.Executable, but that was added in Java 8 // Ideally parameter type would be java.lang.reflect.Executable, but that was added in Java 8
private static void appendExecutableParameters( private static void appendExecutableParameters(
AccessibleObject executable, StringBuilder stringBuilder) { AccessibleObject executable, StringBuilder stringBuilder) {
stringBuilder.append('('); stringBuilder.append('(');
Class<?>[] parameters = Class<?>[] parameters =
(executable instanceof Method) (executable instanceof Method)
? ((Method) executable).getParameterTypes() ? ((Method) executable).getParameterTypes()
: ((Constructor<?>) executable).getParameterTypes(); : ((Constructor<?>) executable).getParameterTypes();
for (int i = 0; i < parameters.length; i++) { for (int i = 0; i < parameters.length; i++) {
if (i > 0) { if (i > 0) {
stringBuilder.append(", "); stringBuilder.append(", ");
...@@ -168,12 +169,12 @@ public class ReflectionHelper { ...@@ -168,12 +169,12 @@ public class ReflectionHelper {
return null; return null;
} catch (Exception exception) { } catch (Exception exception) {
return "Failed making constructor '" return "Failed making constructor '"
+ constructorToString(constructor) + constructorToString(constructor)
+ "' accessible; either increase its visibility or write a custom InstanceCreator or" + "' accessible; either increase its visibility or write a custom InstanceCreator or"
+ " TypeAdapter for its declaring type: " + " TypeAdapter for its declaring type: "
// Include the message since it might contain more detailed information // Include the message since it might contain more detailed information
+ exception.getMessage() + exception.getMessage()
+ getInaccessibleTroubleshootingSuffix(exception); + getInaccessibleTroubleshootingSuffix(exception);
} }
} }
...@@ -196,26 +197,26 @@ public class ReflectionHelper { ...@@ -196,26 +197,26 @@ public class ReflectionHelper {
} }
public static RuntimeException createExceptionForUnexpectedIllegalAccess( public static RuntimeException createExceptionForUnexpectedIllegalAccess(
IllegalAccessException exception) { IllegalAccessException exception) {
throw new RuntimeException( throw new RuntimeException(
"Unexpected IllegalAccessException occurred (Gson " "Unexpected IllegalAccessException occurred (Gson "
+ GsonBuildConfig.VERSION + GsonBuildConfig.VERSION
+ "). Certain ReflectionAccessFilter features require Java >= 9 to work correctly. If" + "). Certain ReflectionAccessFilter features require Java >= 9 to work correctly. If"
+ " you are not using ReflectionAccessFilter, report this to the Gson maintainers.", + " you are not using ReflectionAccessFilter, report this to the Gson maintainers.",
exception); exception);
} }
private static RuntimeException createExceptionForRecordReflectionException( private static RuntimeException createExceptionForRecordReflectionException(
ReflectiveOperationException exception) { ReflectiveOperationException exception) {
throw new RuntimeException( throw new RuntimeException(
"Unexpected ReflectiveOperationException occurred" "Unexpected ReflectiveOperationException occurred"
+ " (Gson " + " (Gson "
+ GsonBuildConfig.VERSION + GsonBuildConfig.VERSION
+ ")." + ")."
+ " To support Java records, reflection is utilized to read out information" + " To support Java records, reflection is utilized to read out information"
+ " about records. All these invocations happens after it is established" + " about records. All these invocations happens after it is established"
+ " that records exist in the JVM. This exception is unexpected behavior.", + " that records exist in the JVM. This exception is unexpected behavior.",
exception); exception);
} }
/** Internal abstraction over reflection when Records are supported. */ /** Internal abstraction over reflection when Records are supported. */
...@@ -306,19 +307,19 @@ public class ReflectionHelper { ...@@ -306,19 +307,19 @@ public class ReflectionHelper {
@Override @Override
String[] getRecordComponentNames(Class<?> clazz) { String[] getRecordComponentNames(Class<?> clazz) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Records are not supported on this JVM, this method should not be called"); "Records are not supported on this JVM, this method should not be called");
} }
@Override @Override
<T> Constructor<T> getCanonicalRecordConstructor(Class<T> raw) { <T> Constructor<T> getCanonicalRecordConstructor(Class<T> raw) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Records are not supported on this JVM, this method should not be called"); "Records are not supported on this JVM, this method should not be called");
} }
@Override @Override
public Method getAccessor(Class<?> raw, Field field) { public Method getAccessor(Class<?> raw, Field field) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Records are not supported on this JVM, this method should not be called"); "Records are not supported on this JVM, this method should not be called");
} }
} }
} }
...@@ -1582,7 +1582,7 @@ public class JsonReader implements Closeable { ...@@ -1582,7 +1582,7 @@ public class JsonReader implements Closeable {
return getClass().getSimpleName() + locationString(); return getClass().getSimpleName() + locationString();
} }
String locationString() { protected String locationString() {
int line = lineNumber + 1; int line = lineNumber + 1;
int column = pos - lineStart + 1; int column = pos - lineStart + 1;
return " at line " + line + " column " + column + " path " + getPath(); return " at line " + line + " column " + column + " path " + getPath();
......
...@@ -65,4 +65,4 @@ public class UtilDeserialisationJson { ...@@ -65,4 +65,4 @@ public class UtilDeserialisationJson {
throw new RuntimeException("Type inattendu: " + typeChamp + ", nom: " + champ.getName()); throw new RuntimeException("Type inattendu: " + typeChamp + ", nom: " + champ.getName());
} }
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment