Courseiva
Exception Handling and Development ToolshardMultiple ChoiceObjective-mapped

1Z0-811 Exception Handling and Development Tools Practice Question

You are a Java developer at a financial firm. The application processes transactions from a queue. The team recently migrated from Java 8 to Java 11. After the migration, the application intermittently throws an exception: 'java.lang.reflect.InaccessibleObjectException: Unable to make field private final byte[] java.lang.String.value accessible: module java.base does not 'opens java.lang' to unnamed module'. This error occurs when the application tries to use reflection to access private fields of String objects for serialization. The application runs on a server where you cannot modify the JVM startup scripts. However, you can modify the application code and the module-info.java file. You need to resolve the exception without breaking existing functionality. Which approach should you take?

⚠ Common exam trap

Oracle often tests the misconception that you can fix module-access errors by adding 'opens' directives in your own module-info.java, but you cannot open packages belonging to other modules (like java.base) from your module descriptor.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Refactor the code to use public APIs instead of reflecting on String's internal fields.

The root cause is that the application uses reflection to access private fields of java.lang.String, which is prohibited in Java 9+ by default due to module system encapsulation. Refactoring to use public APIs (e.g., String.getBytes(), String.charAt()) eliminates the need for reflection entirely, resolving the InaccessibleObjectException without requiring JVM flags or module declarations, and preserves compatibility with Java 11.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Refactor the code to use public APIs instead of reflecting on String's internal fields.

    Why this is correct

    This avoids the module access issue entirely.

  • Add --add-opens java.base/java.lang=ALL-UNNAMED to the JVM command line.

    Why it's wrong here

    You cannot modify JVM startup scripts per the scenario.

  • Use sun.misc.Unsafe to access the String field directly.

    Why it's wrong here

    Unsafe still requires reflection and is not a solution.

  • Add 'opens java.lang;' to the module-info.java file.

    Why it's wrong here

    You cannot open java.lang from your module; it's a system module.

Visual reference

Client Recursive Resolver Root DNS (13 root servers) TLD DNS (.com, .org, …) Authoritative example.com query IP addr answer

About these practice questions

This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.