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

[local-methods] Several problems with Javac's treatment of modifiers for local methods

    Details

    • Type: Bug
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: repo-amber
    • Fix Version/s: repo-amber
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      What modifiers make sense and what don't ?? This needs to be addressed by this ticket.

      (1) strictfp is NOT allowed:

      public class X {
      public static void main(String [] args) {
              strictfp void xxx (int y) {
              }
      }
      }

      X.java:3: error: class, interface, or enum expected
              strictfp void xxx (int y) {
                       ^
      1 error

      (2) final is accepted as a modifier:

      public class X {
      public static void main(String [] args) {
              final void xxx (int y) {
              }
      }
      }

      (3) Is there a valid use case for a local method to be synchronized ??

      (4) If the modifier final is present, then it also becomes possible to have modifiers such as public/protected/private:

      public class X {
      public static void main(String [] args) {
              final public void xxx (int y) { // compiles fine, but public does not make sense for local methods ??
              }
      }
      }

      (5) Tagging a local method abstract results in a compiler crash:

      public class X {
      public static void main(String [] args) {
              @Override
              abstract void xxx (int y);
      }
      }

      java.lang.NullPointerException
      at jdk.compiler/com.sun.tools.javac.comp.Flow$CaptureAnalyzer.visitIdent(Flow.java:2811)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2350)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:405)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitAnnotation(TreeScanner.java:366)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:2674)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:405)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitModifiers(TreeScanner.java:362)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCModifiers.accept(JCTree.java:2703)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:405)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitMethodDef(TreeScanner.java:122)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$CaptureAnalyzer.visitMethodDef(Flow.java:2800)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:875)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:405)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitBlock(TreeScanner.java:143)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1029)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:405)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitMethodDef(TreeScanner.java:129)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$CaptureAnalyzer.visitMethodDef(Flow.java:2805)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:875)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:405)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitClassDef(TreeScanner.java:118)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$CaptureAnalyzer.visitClassDef(Flow.java:2776)
      at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:783)
      at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:405)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$CaptureAnalyzer.analyzeTree(Flow.java:2878)
      at jdk.compiler/com.sun.tools.javac.comp.Flow$CaptureAnalyzer.analyzeTree(Flow.java:2871)
      at jdk.compiler/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:218)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1407)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1381)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:318)
      at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
      at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
      at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

      There could be other issues too. This ticket can be used to make a comprehensive set of changes for modifier handling.







        Attachments

          Activity

            People

            • Assignee:
              sadayapalam Srikanth Adayapalam
              Reporter:
              sadayapalam Srikanth Adayapalam
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: