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

symbol not found error, implicit lambdas and diamond constructor invocations

    XMLWordPrintable

Details

    • b06
    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      debian sid
      Linux 5.10.0-6-amd64 #1 SMP Debian 5.10.28-1 (2021-04-09) x86_64 GNU/Linux
      openjdk 17.0.1 2021-10-19
      OpenJDK Runtime Environment (build 17.0.1+12-Debian-1)
      OpenJDK 64-Bit Server VM (build 17.0.1+12-Debian-1, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      type inference failed with 'cannot find symbol' error

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac Test.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      compiled successfuly
      ACTUAL -
      javac Test.java
      Test.java:25: error: cannot find symbol
                      System.out.println(inHours); //cannot find symbol inHours?
                                         ^
        symbol: variable inHours
      Test.java:31: error: cannot find symbol
                      System.out.println(inHours); //cannot find symbol inHours?
                                         ^
        symbol: variable inHours
      Test.java:37: error: cannot find symbol
                      System.out.println(inHours); //cannot find symbol inHours?
                                         ^
        symbol: variable inHours
      3 errors


      ---------- BEGIN SOURCE ----------
      package bug;

      import java.util.function.Consumer;

      class Test {
          // B must be generic to reproduce
          static class B<T>{}

          static class A1 {
              public <T> A1(Consumer<T> cons) {}
          }

          static class A2<T> {
              public A2(Consumer<T> cons) {}
          }

          static class A3 {
              public <T> A3(T val, Consumer<T> cons) {}
          }

          public void mount() {
              // not works. Expected inHours will be infered as Object
              new A1(inHours ->
                  new B<>() {{
                      System.out.println(inHours); //cannot find symbol inHours?
                  }});

              // not works. Expected inHours will be infered as Object
              new A2<>(inHours ->
                  new B<>() {{
                      System.out.println(inHours); //cannot find symbol inHours?
                  }});

              // not works. Expected inHours will be infered as Boolean
              new A3(true, inHours ->
                  new B<>() {{
                      System.out.println(inHours); //cannot find symbol inHours?
                  }});
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      package bug;

      import java.util.function.Consumer;

      public class Workaround {
          // B must be generic to reproduce
          static class B<T> {}

          static class A1 {
              public <T> A1(Consumer<T> cons) {}
          }

          static class A2<T> {
              public A2(Consumer<T> cons) {}
          }

          static class A3 {
              public <T> A3(T val, Consumer<T> cons) {}
          }

          public void mount() {
              // works (workaround)
              new A1((Consumer<Boolean>) inHours ->
                  new B<>() {{
                      System.out.println(inHours);
                  }});

              // works (workaround)
              new A2<Boolean>(inHours ->
                  new B<>() {{
                      System.out.println(inHours);
                  }});

              // works (workaround)
              new A3(true, (Consumer<Boolean>) inHours ->
                  new B<>() {{
                      System.out.println(inHours);
                  }});
          }
      }


      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: