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

Duplicate variable in lambda causes javac crash

    XMLWordPrintable

Details

    • b96
    • Verified

    Description

      FULL PRODUCT VERSION :
      javac 1.8.0-ea (from jdk-8-ea-bin-b90-linux-x64-16_may_2013.tar.gz)

      ADDITIONAL OS VERSION INFORMATION :
      Linux ... 3.5.0-30-generic #51-Ubuntu SMP Tue May 14 18:47:48 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      NullPointerException compiling the included program.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      CP=/usr/share/java/junit4.jar
      JAVAC=~/jdk1.8.0/bin/javac
      JAVA=~/jdk1.8.0/bin/java

      $JAVAC -cp $CP EBug2.java && $JAVA -cp $CP:. org.junit.runner.JUnitCore EBug2


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expecting tryAdvance() to accept the given Consumer(), and compile (or give proper compile error, maybe)
      ACTUAL -
      See error message.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      An exception has occurred in the compiler (1.8.0-ea). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.NullPointerException
      at com.sun.tools.javac.comp.Check.duplicateError(Check.java:325)
      at com.sun.tools.javac.comp.Check.checkTransparentVar(Check.java:363)
      at com.sun.tools.javac.comp.MemberEnter.visitVarDef(MemberEnter.java:650)
      at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:828)
      at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:419)
      at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1043)
      at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:828)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:648)
      at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:664)
      at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2321)
      at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1590)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:304)
      at com.sun.tools.javac.comp.DeferredAttr$1.complete(DeferredAttr.java:236)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:203)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:191)
      at com.sun.tools.javac.comp.DeferredAttr$RecoveryDeferredTypeMap.recover(DeferredAttr.java:647)
      at com.sun.tools.javac.comp.DeferredAttr$RecoveryDeferredTypeMap.typeOf(DeferredAttr.java:631)
      at com.sun.tools.javac.comp.Resolve$7$ResolveDeferredRecoveryMap.typeOf(Resolve.java:2117)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredTypeMap.apply(DeferredAttr.java:598)
      at com.sun.tools.javac.comp.DeferredAttr$RecoveryDeferredTypeMap.apply(DeferredAttr.java:621)
      at com.sun.tools.javac.code.Type.map(Type.java:219)
      at com.sun.tools.javac.comp.Resolve$7.getArgumentTypes(Resolve.java:2106)
      at com.sun.tools.javac.comp.Resolve.accessInternal(Resolve.java:2025)
      at com.sun.tools.javac.comp.Resolve.accessMethod(Resolve.java:2045)
      at com.sun.tools.javac.comp.Resolve$BasicLookupHelper.access(Resolve.java:2671)
      at com.sun.tools.javac.comp.Resolve$9.access(Resolve.java:2251)
      at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:2906)
      at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2241)
      at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2235)
      at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3259)
      at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3153)
      at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1863)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1802)
      at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1440)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3126)
      at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1863)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1802)
      at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1440)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:621)
      at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1083)
      at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:828)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:648)
      at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:664)
      at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2351)
      at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1590)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:621)
      at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1083)
      at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:828)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:603)
      at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:648)
      at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4172)
      at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4080)
      at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4015)
      at com.sun.tools.javac.comp.Attr.attrib(Attr.java:3989)
      at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1225)
      at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:878)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:837)
      at com.sun.tools.javac.main.Main.compile(Main.java:519)
      at com.sun.tools.javac.main.Main.compile(Main.java:376)
      at com.sun.tools.javac.main.Main.compile(Main.java:365)
      at com.sun.tools.javac.main.Main.compile(Main.java:356)
      at com.sun.tools.javac.Main.compile(Main.java:77)
      at com.sun.tools.javac.Main.main(Main.java:62)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.util.concurrent.Callable;
      import java.util.concurrent.Future;
      import java.util.stream.StreamSupport;
      import java.util.ArrayList;
      import java.util.Spliterators;
      import java.util.concurrent.ExecutorService;
      import java.util.function.Consumer;

      import junit.framework.TestCase;

      public class EBug2 extends TestCase {

      class Pythag {
      public int a, b, c;
      public Pythag( int a, int b, int c ) {
      this.a = a;
      this.b = b;
      this.c = c;
      }
      }

      //* won't compile in b90
      class PythagGenerator extends Spliterators.AbstractSpliterator<Pythag> {
      public PythagGenerator() {
      super( Long.MAX_VALUE, DISTINCT | IMMUTABLE | NONNULL );
      }

      private int a = 1;
      private int b = 2;
      private int c = 3;

      // @Override
      public boolean tryAdvance( Consumer<? super Pythag> p ) {
      /*
      while ( a*a + b*b != c*c ) {
      a++;
      if ( a >= b ) {
      a = 1;
      b++;
      }
      if ( b >= c ) {
      a = 1;
      b = 2;
      c++;
      }
      }
      p.accept( new Pythag( a, b, c ) );
      return true;
      */
      return false;
      }
      }

      Callable<Long> p09 = () -> {
      Pythag p = StreamSupport.stream( new PythagGenerator() ).findFirst( p -> p.a + p.b + p.c == 1000 ).orElse( null );

      return p.a * p.b * p.c;

      /*
      for ( int a = 1; a < 333; a++ ) {
      for ( int b = a + 1; b < 1000 - a; b++ ) {
      int c = 1000 - a - b;
      if ( c <= 0 )
      break;
      if ( a*a + b*b == c*c ) {
      return ( long )( a * b * c );
      }
      }
      }
      return 0L;
      */
      };

      private static ExecutorService pool = null;
      private static Future<Long> fut = null;
      private static ArrayList<Callable<Long>> tasks = new ArrayList<Callable<Long>>();
      @Override public void setUp() {
      if ( pool == null ) {
      pool = Executors.newFixedThreadPool( 5 );
      fut = pool.submit( p09 );
      pool.shutdown();
      }
      }

      public void testP09() {
      assertEquals( 31875000L, fut.get().longValue() );
      }

      public static void main( String[] args ) {
      System.out.print( " pausing for input ... " );
      System.in.read();
      System.out.println( " running " );
      EBug e = new EBug();
      e.setUp();
      System.out.println( " Problem: " + fut.get().longValue() );
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Haven't found one.

      Attachments

        Activity

          People

            mcimadamore Maurizio Cimadamore
            webbuggrp Webbug Group
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: