javac throws a NPE when compiling a lambda expression

Arul Dhesiaseelan aruld at acm.org
Mon Jun 13 05:19:20 PDT 2011


Hmm, my bad, I did not notice that missing import, was using a text editor
to develop lambdas, which proved to be a disaster in this case.

Thanks Maurizio and Ali.

On Mon, Jun 13, 2011 at 4:41 AM, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

> On 13/06/11 11:37, Ali Ebrahimi wrote:
> > Hi Maurizio,
> > similar crash for this code:
> >                             call(#{ -> System.out.println(
> > undefinedVar );  });
> Yeah, all these problems have gone now (fixed in the latest push).
> Thanks for the headsup.
>
> Maurizio
> > Ali Ebrahimi
> >
> > On Mon, Jun 13, 2011 at 12:07 PM, Maurizio Cimadamore
> > <maurizio.cimadamore at oracle.com
> > <mailto:maurizio.cimadamore at oracle.com>> wrote:
> >
> >     I confirm that the following simplified example actually fails
> >     with the latest compiler:
> >
> >     class TestLambda {
> >
> >
> >      interface SAM {
> >        void m();
> >      }
> >
> >      {
> >        call(#{ -> log(new Date() + "");  });
> >      }
> >
> >      void call(SAM s) { }
> >
> >
> >      void log(String msg) {
> >        System.out.println(msg);
> >      }
> >      }
> >
> >     The problem is caused by a bad error recovery - in the above
> >     example java.util.Date cannot be found, because the corresponding
> >     import is missing. Which means that the compiler should emit an
> >     error, but in this case the error is swallen when attributing the
> >     lambda body - which means that the compiler tries to emit code for
> >     an incorrect source program - hence the NPE.
> >
> >     Maurizio
> >
> >
> >
> >     On 13/06/11 07:46, Ali Ebrahimi wrote:
> >
> >         Hi,
> >         This sample code compiles with current lambda repository build.
> >
> >         Ali Ebrahimi
> >
> >         On Sat, Jun 11, 2011 at 9:00 AM, Arul
> >         Dhesiaseelan<aruld at acm.org <mailto:aruld at acm.org>>  wrote:
> >
> >             public class TestLambda {
> >
> >              class Payment {
> >                private int amount;
> >
> >                Payment(int amount) {
> >                  this.amount = amount;
> >                }
> >
> >                public int getAmount() {
> >                  return amount;
> >                }
> >              }
> >
> >              interface PaymentProcessor {
> >                void process(Payment pmt);
> >              }
> >
> >              {
> >                invokeProcessor(# { pmt ->  log("Processed # " +
> >             pmt.getAmount() + " at
> >             " + new Date()) });
> >              }
> >
> >              void invokeProcessor(PaymentProcessor processor) {
> >                processor.process(new Payment(42));
> >              }
> >
> >              void log(String msg) {
> >                System.out.println(msg);
> >              }
> >             }
> >
> >             I am trying to rebuild my old Lambda example (which used
> >             to work with
> >             earlier prototype using build 115), but failed to compile
> >             with the latest
> >             prototype using build 145:
> >
> >             An exception has occurred in the compiler
> >             (1.7.0-internal). 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.Flow.visitNewClass(Flow.java:1308)
> >                    at
> >
> com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1391)
> >                    at
> >
> com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
> >                    at
> >             com.sun.tools.javac.comp.Flow.scanExpr(Flow.java:572)
> >                    at
> >             com.sun.tools.javac.comp.Flow.visitBinary(Flow.java:1504)
> >                    at
> >
> com.sun.tools.javac.tree.JCTree$JCBinary.accept(JCTree.java:1654)
> >                    at
> >
> com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
> >                    at
> >             com.sun.tools.javac.comp.Flow.scanExpr(Flow.java:572)
> >                    at
> >             com.sun.tools.javac.comp.Flow.scanExprs(Flow.java:582)
> >                    at
> >             com.sun.tools.javac.comp.Flow.visitApply(Flow.java:1299)
> >                    at
> >
> com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1337)
> >                    at
> >
> com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
> >                    at
> >             com.sun.tools.javac.comp.Flow.scanStat(Flow.java:556)
> >                    at
> >             com.sun.tools.javac.comp.Flow.analyzeLambda(Flow.java:1370)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribLambda(Attr.java:2314)
> >                    at
> >             com.sun.tools.javac.comp.Attr$1.deferredAttr(Attr.java:2194)
> >                    at
> >             com.sun.tools.javac.comp.Attr$1.deferredAttr(Attr.java:2185)
> >                    at
> >
> >
> com.sun.tools.javac.comp.Attr$SAMDeferredAttribution.complete(Attr.java:2793)
> >                    at
> >
> com.sun.tools.javac.comp.Infer$InferPolyCompleter.complete(Infer.java:737)
> >                    at
> >
> com.sun.tools.javac.comp.Infer.instantiatePoly(Infer.java:748)
> >                    at
> >
> >
> com.sun.tools.javac.comp.Resolve.checkRawArgumentsAcceptable(Resolve.java:553)
> >                    at
> >
> com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:419)
> >                    at
> >
> com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:396)
> >                    at
> >             com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:820)
> >                    at
> >
> com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1064)
> >                    at
> >
> com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1025)
> >                    at
> >             com.sun.tools.javac.comp.Resolve.findFun(Resolve.java:1158)
> >                    at
> >
> com.sun.tools.javac.comp.Resolve.resolveMethod(Resolve.java:1582)
> >                    at
> >             com.sun.tools.javac.comp.Attr.visitIdent(Attr.java:2546)
> >                    at
> >
> com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:1826)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribTree(Attr.java:466)
> >                    at
> >             com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1578)
> >                    at
> >
> com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1337)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribTree(Attr.java:466)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribTree(Attr.java:484)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:499)
> >                    at
> >             com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1334)
> >                    at
> >
> >
> com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1180)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribTree(Attr.java:466)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribTree(Attr.java:484)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribStat(Attr.java:519)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribStats(Attr.java:535)
> >                    at
> >             com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:952)
> >                    at
> >
> com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:794)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribTree(Attr.java:466)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribTree(Attr.java:484)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribStat(Attr.java:519)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:3793)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribClass(Attr.java:3715)
> >                    at
> >             com.sun.tools.javac.comp.Attr.attribClass(Attr.java:3651)
> >                    at
> com.sun.tools.javac.comp.Attr.attrib(Attr.java:3625)
> >                    at
> >
> com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1189)
> >                    at
> >
> com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:877)
> >                    at
> >
> com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:836)
> >                    at
> com.sun.tools.javac.main.Main.compile(Main.java:417)
> >                    at
> com.sun.tools.javac.main.Main.compile(Main.java:331)
> >                    at
> com.sun.tools.javac.main.Main.compile(Main.java:322)
> >                    at com.sun.tools.javac.Main.compile(Main.java:76)
> >                    at com.sun.tools.javac.Main.main(Main.java:61)
> >
> >
> >             java version "1.7.0-ea"
> >             Java(TM) SE Runtime Environment (build 1.7.0-ea-b145)
> >             Java HotSpot(TM) 64-Bit Server VM (build 21.0-b15, mixed
> mode)
> >
> >             I am not sure what has changed since then. Any clues?
> >
> >             -Arul
> >
> >
> >
> >
>
>
>


More information about the lambda-dev mailing list