Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8227010

Error recovery after local variable redeclaration can be improved

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 14
    • Fix Version/s: 14
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b05

      Description

      Consider code like this:
      ---
      public class T {
          {
               String v = "";
               Integer v = 0;
               System.err.println(v.byteValue());
          }
      }
      ---

      The errors for this code is:
      ---
      $ javac T.java
      T.java:4: error: variable v is already defined in instance initializer of class T
               Integer v = 0;
                       ^
      T.java:5: error: cannot find symbol
               System.err.println(v.byteValue());
                                   ^
        symbol: method byteValue()
        location: variable v of type String
      2 errors
      ---

      The first error is correct, of course, but the second error seems unnecessary - the variable is "redeclared", so it seems from the point of redeclaration, "v" should mean the new variable.

        Attachments

          Activity

            People

            • Assignee:
              jlahoda Jan Lahoda
              Reporter:
              jlahoda Jan Lahoda
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: