JDK 8148716: Variable proxy duplicate

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Feb 9 01:00:12 UTC 2017


Hi,
I believe that to be a duplicate of

https://bugs.openjdk.java.net/browse/JDK-8169345

for which we have a fix in the works which we'll push to 10 soon.

Srikanth and I decided to go for a more radical rewriting in the area, 
making a lot of the logic in the code (now implicit in the use of the 
Scope data structure) more explicit and less prone to errors of this sort.

Thanks
Maurizio



On 08/02/17 22:02, B. Blaser wrote:
> Hi,
>
> Javac fails to compile the following example because it creates twice
> the same variable proxy (jdk 8148716):
>
> class A {
>      public static void main(String... args) {
>          new A().a();
>      }
>
>      void a() {
>          String x = "abc";
>
>          class B {
>              public int b() { return x.length(); }
>          };
>
>          Runnable r = () -> {
>              class C {
>                  void c() {
>                      // free var x in a()
>                      System.out.println(new B().b());
>                      // free var x in lambda()
>                      System.out.println(x.length());
>                  }
>              }
>              new C().c();
>          };
>          r.run();
>      }
> }
>
> ... once for x in a() and once for x in lambda().
>
> The fix below prevents free variable duplicate regardless of the owner
> (Lower.FreeVarCollector.addFreeVar()), ensuring no proxy duplication
> (see proxies.getSymbolsByName() in Lower.initField()).
>
> Needs to be well tested...
>
> Any comment is welcome!
>
> Thanks,
> Bernard
>
> diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> @@ -289,7 +289,7 @@
>            */
>           private void addFreeVar(VarSymbol v) {
>               for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail)
> -                if (l.head == v) return;
> +                if (l.head.name == v.name) return;
>               fvs = fvs.prepend(v);
>           }



More information about the compiler-dev mailing list