Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Java errors surface at different stages: some stop a program from compiling, while others appear only when code runs. This checklist covers 50 recurring mistakes—not a measured ranking—and gives a symptom, likely cause, and practical way to prevent or investigate each one. Use the compiler’s exact diagnostics, the first relevant application frame in a stack trace, and the JDK version your project targets to narrow the search.

Compile-time and build mistakes

The compiler can catch syntax, type, access, and control-flow problems before a program runs. A compiler error often points near the cause, but a missing delimiter or brace can produce follow-on errors elsewhere. Fix the earliest credible diagnostic first, then rebuild.

  1. Missing semicolon or delimiter

    Symptom: A syntax error appears at a line that otherwise looks valid. Likely cause: A statement is missing a semicolon, comma, parenthesis, or other required delimiter, sometimes on the preceding line. Prevent or debug: Inspect the reported line and the expression immediately before it; fix the first parser error before chasing later diagnostics.

  2. Mismatched braces or parentheses

    Symptom: The compiler reports an unexpected end of file, an illegal start, or errors in code that appears to be inside the wrong block. Likely cause: An opening brace or parenthesis has no matching close, or blocks are nested incorrectly. Prevent or debug: Use IDE bracket matching or formatting, and reduce deeply nested blocks where practical.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Misspelled identifier

    Symptom: A variable, method, or type cannot be found. Likely cause: A use does not exactly match the declared name. Prevent or debug: Compare declaration and use, and use compiler suggestions, IDE completion, or rename/refactor tools rather than retyping identifiers.

  4. Incorrect capitalization

    Symptom: A name that looks correct is still unresolved. Likely cause: Java identifiers are case-sensitive, so total and Total are different names. Prevent or debug: Match capitalization exactly and use consistent naming conventions.

  5. Type mismatch

    Symptom: The compiler rejects an assignment, argument, or return expression. Likely cause: The value’s type is incompatible with the declared destination. Prevent or debug: Align the types at the API boundary. Use a conversion or cast only when it preserves the intended meaning and range.

  6. Incompatible method argument

    Symptom: A method call has no applicable overload, or an argument cannot be converted to the parameter type. Likely cause: The call supplies the wrong number or type of arguments. Prevent or debug: Check the method signature and overloads at the call site; pass the intended value rather than forcing an unsafe cast.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  7. Missing return on a code path

    Symptom: A non-void method is rejected because not all paths return a value. Likely cause: One branch can finish without returning. Prevent or debug: Trace every branch, including fall-through cases, and return an appropriate result or restructure the control flow.

  8. Returning the wrong type

    Symptom: A return statement fails type checking. Likely cause: The expression does not match the method’s declared return type. Prevent or debug: Compare the method contract with every returned expression; change the implementation or signature only if that reflects the intended API.

  9. Unhandled checked exception

    Symptom: Compilation requires a catch or a throws declaration. Likely cause: A called operation declares a checked exception. Checked exceptions have a catch-or-declare requirement; for example, Oracle’s exception tutorial uses IOException to illustrate the distinction from unchecked exceptions (Oracle: Catch or Specify Requirement). Prevent or debug: Catch the exception where meaningful recovery or context is available, or declare it with throws so callers can decide how to handle it.

  10. Catching an exception that cannot be thrown

    Symptom: A checked-exception catch block is rejected as unreachable. Likely cause: The relevant code in the try block cannot throw that checked type. Prevent or debug: Verify the API’s declared exceptions and simplify or relocate the handler to the operation that can actually fail.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  11. Unreachable statement

    Symptom: The compiler identifies code that cannot execute. Likely cause: A statement follows an unconditional return, throw, or other terminating flow. Prevent or debug: Remove dead code or correct the branch structure so the intended statement is reachable.

  12. Duplicate local declaration

    Symptom: A local variable name is reported as already defined. Likely cause: The same local name is declared again within an overlapping scope. Prevent or debug: Reuse the existing variable or choose a name that makes the second value’s purpose clear.

  13. Inaccessible member

    Symptom: A field, constructor, or method is reported as private or otherwise inaccessible. Likely cause: The code violates the member’s visibility or package-access rules. Prevent or debug: Use the class’s public or protected API; change visibility only when the design genuinely calls for a broader contract.

  14. Incorrect import or package declaration

    Symptom: A type cannot be resolved or the build reports a package/layout mismatch. Likely cause: The declared package, source directory, import, or actual type name is inconsistent. Prevent or debug: Check the type’s package and the project’s source layout, then correct the declaration or import.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  15. Calling an instance member from a static context

    Symptom: A static method or initializer cannot reference an instance field or method. Likely cause: The code uses per-object state without an object reference. Prevent or debug: Call through an appropriate instance, or make the member static only if it represents class-level behavior rather than object state.

  16. Override signature mismatch

    Symptom: A method intended to override a parent method is treated as a different method or fails compilation. Likely cause: Its name, parameters, or return type does not satisfy the override rules. Prevent or debug: Add @Override so the compiler checks the intent, then match the inherited signature and permitted return-type rules.

  17. Incorrect generic type

    Symptom: A generic API rejects a value or produces an incompatible-type diagnostic. Likely cause: A declaration or call uses a type parameter inconsistent with the values it handles. Prevent or debug: Carry the intended type parameter through declarations and method calls instead of relying on unchecked conversions.

  18. Raw-type use

    Symptom: Generic code emits unchecked warnings or permits values of unintended types. Likely cause: A generic class is used without its type argument, such as List instead of List<String>. Prevent or debug: Parameterize the type so the compiler can check values when they enter and leave the collection.

    Free tools Windows power users keep installed

    One-click scans. No signup required.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  19. Uninitialized local variable

    Symptom: A local variable cannot be read because it might not have been initialized. Likely cause: At least one control-flow path reaches the read without an assignment. Prevent or debug: Assign a meaningful value on every path before use; avoid arbitrary defaults that disguise missing logic.

  20. Wrong operator or expression precedence

    Symptom: The program compiles but a condition or calculation gives an unexpected result. Likely cause: An operator is wrong or the expression groups differently from what the author intended. Prevent or debug: Add parentheses to make intent explicit and test boundary cases, especially around mixed arithmetic and boolean operators.

Runtime and data mistakes

Runtime problems pass compilation but fail for particular values, states, or operation order. Reproduce them with the smallest input that triggers the failure, then inspect the value and invariant at the access or calculation site.

  1. Null dereference

    Symptom: A NullPointerException occurs when code accesses a field or calls a method through a null reference. Likely cause: A value expected to refer to an object was never set, was explicitly cleared, or was returned as null. Prevent or debug: Check the failing reference and trace where it came from; validate external input and define clear non-null contracts where appropriate. Oracle’s API documentation describes this exception.

    What’s actually slowing this PC down?

    Pick the symptom - the matching free tool is one click away.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  2. Array index out of bounds

    Symptom: An array access throws ArrayIndexOutOfBoundsException. Likely cause: The index is negative or is at least the array length. Prevent or debug: Ensure 0 <= index && index < array.length; test empty arrays and the first and last valid positions. The Java Language Specification covers array access and its runtime checks in Chapter 15, section 15.10.4.

  3. Collection index out of bounds

    Symptom: An indexed list access throws IndexOutOfBoundsException. Likely cause: The index is outside the collection’s current valid range, or the collection changed between checking and accessing it. Prevent or debug: Compare against the current size at the access point, account for mutation, and review the method’s documented index range. Oracle’s tutorial distinguishes this unchecked exception from checked exceptions (Catch or Specify Requirement).

  4. Off-by-one loop bound

    Symptom: A loop skips the final item or attempts one beyond it. Likely cause: The bound does not match the collection or array’s exclusive upper limit. Prevent or debug: For indexed traversal, use a condition such as i < length, and test zero, one, and several elements.

  5. Dividing an integer by zero

    Symptom: Integer division with a zero divisor throws ArithmeticException. Likely cause: The input or computed divisor is zero. Prevent or debug: Validate the divisor and define the correct behavior for zero rather than relying on an exception as normal control flow. The language specification describes integer division by zero in Chapter 15, section 15.17.2.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  6. Numeric overflow or truncation

    Symptom: A result wraps, loses a fractional part, or changes unexpectedly after conversion. Likely cause: The chosen type cannot represent the value or a narrowing cast discards information. Prevent or debug: Choose a type suited to the domain’s range and precision, and test values near its limits before converting.

  7. Number parsing failure

    Symptom: Parsing input as a number throws a parsing exception. Likely cause: The text is malformed or does not follow the expected numeric format. Prevent or debug: Validate input at the boundary, define accepted formats, and handle invalid text with a useful message or recovery path.

  8. Comparing strings with ==

    Symptom: Two strings with the same characters compare as unequal. Likely cause: == tests whether references identify the same object, not whether string contents match. Prevent or debug: Use equals or an appropriate null-safe comparison for content equality, and decide explicitly how null should be treated.

  9. Incorrect substring range

    Symptom: A substring operation throws an index-related exception or returns an unexpected portion. Likely cause: The start/end positions are reversed or outside the string’s bounds. Prevent or debug: Check the API’s inclusive/exclusive range convention and verify the indices against the string length before extracting.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  10. Modifying a collection during iteration

    Symptom: Iteration fails or skips elements after the collection changes. Likely cause: The collection is structurally modified through an unsupported path while its iterator is active. Prevent or debug: Use the iterator’s supported removal operation, or collect elements to change and apply the changes after traversal.

  11. Using a stale or wrong map key

    Symptom: A map lookup returns no value even though a seemingly equivalent key was inserted. Likely cause: The lookup key differs under equality rules, normalization differs, or a key’s state changed. Prevent or debug: Check key construction, normalization, and equals/hashCode behavior at insertion and lookup.

  12. Assuming input is non-empty

    Symptom: An operation fails on empty text, a collection, or a file. Likely cause: Code assumes at least one value exists before reading, indexing, or taking a first element. Prevent or debug: Handle the empty case explicitly before accessing content and decide whether it is valid input or an error.

  13. Incorrect boolean condition

    Symptom: A branch runs for the wrong inputs or fails to run at a boundary. Likely cause: The condition uses the wrong combination of &&, ||, or negation. Prevent or debug: Write a small truth table for the intended cases and test values exactly at each boundary.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  14. Accidental integer division

    Symptom: A calculation expected to be fractional produces a whole-number result. Likely cause: Both operands are integral, so the division discards the fractional portion. Prevent or debug: Use an appropriate floating-point or decimal representation when fractional precision is required, and consider rounding requirements explicitly.

  15. Unsafe cast

    Symptom: A cast compiles but fails at runtime with ClassCastException. Likely cause: The object is not actually an instance of the assumed type. Prevent or debug: Prefer polymorphic methods or a type-safe design; if a runtime type distinction is necessary, verify it before casting.

  16. Confusing object identity with value equality

    Symptom: Distinct objects representing the same domain value do not compare as equal. Likely cause: Identity comparison is used, or a domain class has not implemented the equality contract it needs. Prevent or debug: Use value equality for value comparisons and implement equals and hashCode consistently when objects serve as domain values or keys.

  17. Mutable object used as a hash key

    Symptom: A key inserted into a hash-based collection becomes difficult to find after its fields change. Likely cause: Mutation changed information used by its hash or equality behavior. Prevent or debug: Keep key state stable while it is stored, or remove the key before changing it and insert it again afterward.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  18. Incorrect date or time assumptions

    Symptom: A date shifts, a time is interpreted unexpectedly, or a comparison fails across regions. Likely cause: The code assumes a time zone, calendar meaning, or fixed offset that was not specified. Prevent or debug: Use a date/time type appropriate to the task and make time-zone assumptions explicit at input, storage, and display boundaries.

  19. Resource leak

    Symptom: Files, streams, or similar resources remain open after work finishes, potentially exhausting operating-system or application resources. Likely cause: Cleanup is skipped on an exception or an early return. Prevent or debug: Use try-with-resources for resources that implement the applicable closeable resource contract, so closure occurs when the block exits. Oracle explains the construct in The try-with-resources Statement.

  20. Swallowing an exception

    Symptom: An operation fails but the program continues with missing or misleading results. Likely cause: A catch block ignores the exception or logs too little context. Prevent or debug: Recover only when there is a sound recovery action; otherwise report or propagate the failure with useful context. Do not leave a catch block empty merely to silence the compiler.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Exception handling, APIs, and debugging

An exception is an event during program execution that disrupts the normal flow of instructions, as Oracle describes in The Java Tutorials: Lesson: Exceptions. Checked exceptions require catching or declaring; unchecked runtime exceptions do not. The Java Language Specification defines exception behavior for the specified release, so verify details against the JDK your project targets.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Catching overly broad exceptions

    Symptom: One handler treats unrelated failures alike or hides bugs that should surface. Likely cause: The code catches a broad type without a recovery strategy for every condition it includes. Prevent or debug: Catch the narrow exception types the current layer can meaningfully handle; let other failures propagate to an appropriate boundary.

  2. Catching Error as routine control flow

    Symptom: The program attempts to continue after a serious virtual-machine or linkage failure. Likely cause: Error is handled like an ordinary recoverable exception. Prevent or debug: Do not use Error as a routine recovery mechanism; distinguish it from exceptions your application can reasonably handle.

  3. Using unchecked exceptions to avoid documenting recoverable failures

    Symptom: Callers encounter a failure they could have anticipated but were given no checked contract or clear API behavior. Likely cause: The exception type was chosen to avoid a declaration rather than to reflect the failure and caller’s options. Prevent or debug: Choose checked versus unchecked behavior based on whether callers can reasonably recover and on the API’s intended contract.

  4. Losing the original cause when wrapping an exception

    Symptom: A higher-level error message appears, but the lower-level failure cannot be diagnosed. Likely cause: A new exception is thrown without attaching the caught exception as its cause. Prevent or debug: When translating an exception, use a constructor or API that preserves the original cause and add context that explains the higher-level operation.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  5. Returning a misleading default after failure

    Symptom: A caller receives a plausible value even though the requested operation failed. Likely cause: A catch block returns a default such as zero, an empty string, or null without defining that value as a valid fallback. Prevent or debug: Make failure visible through the method’s contract, an appropriate exception, or a clearly defined fallback result.

  6. Logging and rethrowing at every layer

    Symptom: One failure produces repeated stack traces without helping identify where recovery belongs. Likely cause: Each layer logs the same exception and rethrows it unchanged. Prevent or debug: Add context at boundaries that contribute useful information; otherwise preserve and propagate the exception without duplicating noise.

  7. Incorrect catch order

    Symptom: A specific handler is unreachable or a broad handler intercepts failures intended for a narrower one. Likely cause: Catch blocks are ordered from specific to broad incorrectly. Prevent or debug: Put more specific exception types before their broader supertypes and keep each handler focused on its recovery action.

  8. Relying on exception messages as machine-readable values

    Symptom: Error handling breaks when wording changes or differs between environments. Likely cause: Code branches on message text instead of exception type or structured data. Prevent or debug: Use exception classes, error codes, or an explicit result structure for program logic; reserve messages for human-readable diagnostics.

    What’s actually slowing this PC down?

    Pick the symptom - the matching free tool is one click away.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  9. Ignoring compiler/runtime version mismatch

    Symptom: Code compiles in one environment but fails or behaves differently in another. Likely cause: The configured compiler, build target, and runtime JDK do not align. Prevent or debug: Check the JDK used by the build and deployment, and align the project’s source/target or release configuration with the runtime requirements. Oracle labels its exception tutorial as JDK 8-era material and directs readers to newer learning resources; verify language and API advice against your target JDK (Oracle Java Tutorials).

  10. Reading only the final stack-trace line

    Symptom: Debugging focuses on a low-level frame without locating the application operation that led to it. Likely cause: The exception type, message, first relevant application frame, or causal chain is overlooked. Prevent or debug: Read the exception heading and message, find the first stack frame in your code, inspect causes, then reproduce with the smallest input that still fails.

How to use this checklist when an error appears

  • If the program does not compile: Start with the first credible compiler diagnostic, inspect its nearby code and types, and rebuild after fixing it. Later parser errors can be consequences of an earlier delimiter or declaration problem.
  • If it fails only for certain data: Capture the smallest failing input and inspect nullability, ranges, empty cases, numeric boundaries, equality behavior, and collection changes at the point of failure.
  • If an exception occurs: Identify its type and origin, decide whether the current layer can recover, preserve the cause when translating it, and ensure cleanup happens on both success and failure.
  • If guidance seems inconsistent: Check the language or API version it describes and compare it with the JDK configured for compilation and execution.

The Oracle Java Tutorials’ exception lesson explicitly says it was written for JDK 8 and may not include later improvements; it points readers toward Dev.java learning materials for newer tutorials. The linked Java Language Specification chapter is for Java SE 26, so its version-specific details should not automatically be assumed for every older runtime.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.