{"id":"593b5b441da3a81c","repo":"google/gson","slug":"failed-making-description-accessible-eith","errorCode":null,"errorMessage":"Failed making \" + description + \" accessible; either increase its visibility or write a custom TypeAdapter for its declaring type.\" + getInaccessibleTroubleshootingSuffix(exception)","messagePattern":"Failed making \" \\+ description \\+ \" accessible; either increase its visibility or write a custom TypeAdapter for its declaring type\\.\" \\+ getInaccessibleTroubleshootingSuffix\\(exception\\)","errorType":"exception","errorClass":"JsonIOException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java","lineNumber":71,"sourceCode":"              : \"reflection-inaccessible\";\n      return \"\\nSee \" + TroubleshootingGuide.createUrl(troubleshootingId);\n    }\n    return \"\";\n  }\n\n  /**\n   * Internal implementation of making an {@link AccessibleObject} accessible.\n   *\n   * @param object the object that {@link AccessibleObject#setAccessible(boolean)} should be called\n   *     on.\n   * @throws JsonIOException if making the object accessible fails\n   */\n  public static void makeAccessible(AccessibleObject object) throws JsonIOException {\n    try {\n      object.setAccessible(true);\n    } catch (Exception exception) {\n      String description = getAccessibleObjectDescription(object, false);\n      throw new JsonIOException(\n          \"Failed making \"\n              + description\n              + \" accessible; either increase its visibility\"\n              + \" or write a custom TypeAdapter for its declaring type.\"\n              + getInaccessibleTroubleshootingSuffix(exception),\n          exception);\n    }\n  }\n\n  /**\n   * Returns a short string describing the {@link AccessibleObject} in a human-readable way. The\n   * result is normally shorter than {@link AccessibleObject#toString()} because it omits modifiers\n   * (e.g. {@code final}) and uses simple names for constructor and method parameter types.\n   *\n   * @param object object to describe\n   * @param uppercaseFirstLetter whether the first letter of the description should be uppercased\n   */\n  public static String getAccessibleObjectDescription(","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/google/gson/blob/8b8628c65699bc4421696183c62ae0c1b9b281dc/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java#L53-L89","documentation":"ReflectionHelper.makeAccessible calls setAccessible(true) on a Field/Method/Constructor and catches any exception, wrapping it as JsonIOException. On Java 9+ the typical cause is InaccessibleObjectException because the declaring module does not open the package to Gson; the message appends a troubleshooting URL when that is detected.","triggerScenarios":"Deserializing a class whose private fields are in a module (JDK or your own named module) that has not opened its package to Gson, or running under a SecurityManager that denies reflective access.","commonSituations":"Mapping JDK types (e.g. java.time, java.net) without a custom adapter, migrating to JPMS modules, upgrading to Java 16+ where strong encapsulation is enforced, or libraries that sealed their internals.","solutions":["Add '--add-opens <module>/<package>=com.google.gson' (or ALL-UNNAMED) to your JVM launch args.","If you own the module, add 'opens <package> to com.google.gson;' in module-info.java.","Increase the field's visibility to package-public, or annotate it for Gson access.","Register a custom TypeAdapter for the declaring type to avoid reflection entirely.","Configure ReflectionAccessFilter to allow or block access intentionally."],"exampleFix":"// before: deserializing a class in a non-open module throws\nMyType obj = gson.fromJson(json, MyType.class);\n\n// after: open the package at launch\n// java --add-opens com.example/com.example.internal=ALL-UNNAMED -jar app.jar\n// or in module-info.java of com.example:\n// opens com.example.internal to com.google.gson;","handlingStrategy":"try-catch","validationCode":"// No code-only validation; check module openness reflectively before Gson use.\nboolean canAccess(Class<?> c, Field f) {\n  try { f.setAccessible(true); return true; }\n  catch (RuntimeException e) { return false; }\n  finally { /* module not opened to your code either */ }\n}","typeGuard":"static boolean isLikelyAccessible(Class<?> c) {\n  return Modifier.isPublic(c.getModifiers()) || java.util.Arrays.stream(c.getDeclaredFields()).anyMatch(f -> Modifier.isPublic(f.getModifiers()));\n}","tryCatchPattern":"try {\n  T obj = gson.fromJson(json, type);\n} catch (JsonIOException e) {\n  if (e.getMessage().contains(\"Failed making\") && e.getCause() instanceof InaccessibleObjectException) {\n    // add --add-opens or a custom TypeAdapter, then retry\n  } else throw e;\n}","preventionTips":["Document required --add-opens in your run scripts and build files.","Prefer public fields or custom TypeAdapters for third-party/module types.","Run integration tests on the target JDK to catch module-access failures in CI."],"tags":["gson","reflection","jpms","java-modules","encapsulation"],"analyzedSha":"8b8628c65699bc4421696183c62ae0c1b9b281dc","analyzedAt":"2026-08-04T19:12:22.202Z","schemaVersion":2}