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

NullPointerException Trying to Compile Code

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u31
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_31"
      Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      None that I am aware of.

      A DESCRIPTION OF THE PROBLEM :
      When trying to compile a class using lambda expressions, the javac throws a null pointer exception with detailed stack trace.

      ADDITIONAL REGRESSION INFORMATION:
      It has not worked on prior releases of java 8.

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

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect class to compile
      ACTUAL -
      Null pointer exception

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      An exception has occurred in the compiler (1.8.0_31). 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$AbstractAssignAnalyzer.visitIdent(Flow.java:2380)
              at com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2011)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
              at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
              at com.sun.tools.javac.tree.TreeScanner.visitReference(TreeScanner.java:268)
              at com.sun.tools.javac.tree.JCTree$JCMemberReference.accept(JCTree.java:1973)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
              at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
              at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scanExpr(Flow.java:1627)
              at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scanExprs(Flow.java:1639)
              at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.visitApply(Flow.java:2236)
              at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
              at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:398)
              at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.scan(Flow.java:1376)
              at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.analyzeTree(Flow.java:2423)
              at com.sun.tools.javac.comp.Flow$AbstractAssignAnalyzer.analyzeTree(Flow.java:2406)
              at com.sun.tools.javac.comp.Flow.analyzeLambdaThrownTypes(Flow.java:250)
              at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2423)
              at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.DeferredAttr$2.complete(DeferredAttr.java:284)
              at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:245)
              at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:232)
              at com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:993)
              at com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:826)
              at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:731)
              at com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:835)
              at com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:162)
              at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:564)
              at com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:601)
              at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3809)
              at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3615)
              at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3522)
              at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3501)
              at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3488)
              at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3370)
              at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
              at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:656)
              at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1611)
              at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
              at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
              at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
              at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
              at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
              at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
              at com.sun.tools.javac.main.Main.compile(Main.java:523)
              at com.sun.tools.javac.main.Main.compile(Main.java:381)
              at com.sun.tools.javac.main.Main.compile(Main.java:370)
              at com.sun.tools.javac.main.Main.compile(Main.java:361)
              at com.sun.tools.javac.Main.compile(Main.java:56)
              at com.sun.tools.javac.Main.main(Main.java:42)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /******************************************************************************
       *
       * Filename: JavacError.java
       * Description:
       *
       * (c) COPYRIGHT Queen City Software, Inc. 2014 All Rights Reserved
       * No part of this copyrighted work may be reproduced, modified, or distributed
       * in any form or by any means without the prior written permission of Queen
       * City Software, Inc.
       *
       * $Id$
       * Notes:
       *
       *****************************************************************************/
      package com.qcsoftware.products.fulfillmentmgr;

      import java.util.concurrent.atomic.AtomicInteger;
      import java.util.function.Consumer;

      /**
       * The {@code JavacError} class.
       */
      public class JavacError
      {
        public static void main(String[] args)
        {
          AtomicInteger status = new AtomicInteger(0);
          String response = "";

          /*
           * This way causes exception in javac
           */
          new DbResource()
            .transaction(DbResource.actions(
                           dbr -> System.out.println("hello world")),
                         res -> handleException(res,
                                                response,
                                                status),
                         DbResource::commitAndClose);
          
          /*
           * This way works in javac
           */
      // ConsumerThrower<DbResource, RuntimeException> catcher =
      // res -> handleException(res,
      // response,
      // status);
      // new DbResource()
      // .transaction(DbResource.actions(
      // dbr -> System.out.println("hello world")),
      // catcher,
      // DbResource::commitAndClose);
        }

        private static ConsumerThrower<DbResource, RuntimeException> handleException(DbResource res,
                                                                                     String response,
                                                                                     AtomicInteger status)
        {
          throw new UnsupportedOperationException("Not supported yet.");
        }
        
        private static class DbResource
        {
          @SafeVarargs
          public static final ConsumerThrower<DbResource, ?>[] actions(
              ConsumerThrower<DbResource, ?>... action)
          {
            return action;
          }
          
          public static void commitAndClose(DbResource dbr)
          {
            throw new UnsupportedOperationException("Not supported yet.");
          }
          
          public final <T extends Throwable> void transaction(
              ConsumerThrower<DbResource, ?>[] action,
              ConsumerThrower<DbResource, T> catcher,
              Consumer<DbResource> finalizer
              ) throws T
          {
            throw new UnsupportedOperationException("Not supported yet.");
          }
        }
        
        @FunctionalInterface
        public static interface ConsumerThrower<A, T extends Throwable>
        {
          public void accept(A arg) throws T;
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      /******************************************************************************
       *
       * Filename: JavacError.java
       * Description:
       *
       * (c) COPYRIGHT Queen City Software, Inc. 2014 All Rights Reserved
       * No part of this copyrighted work may be reproduced, modified, or distributed
       * in any form or by any means without the prior written permission of Queen
       * City Software, Inc.
       *
       * $Id$
       * Notes:
       *
       *****************************************************************************/
      package com.qcsoftware.products.fulfillmentmgr;

      import java.util.concurrent.atomic.AtomicInteger;
      import java.util.function.Consumer;

      /**
       * The {@code JavacError} class.
       */
      public class JavacError
      {
        public static void main(String[] args)
        {
          AtomicInteger status = new AtomicInteger(0);
          String response = "";

          /*
           * This way causes exception in javac
           */
      // new DbResource()
      // .transaction(DbResource.actions(
      // dbr -> System.out.println("hello world")),
      // res -> handleException(res,
      // response,
      // status),
      // DbResource::commitAndClose);
          
          /*
           * This way works in javac
           */
          ConsumerThrower<DbResource, RuntimeException> catcher =
            res -> handleException(res,
                                   response,
                                   status);
          new DbResource()
            .transaction(DbResource.actions(
                           dbr -> System.out.println("hello world")),
                         catcher,
                         DbResource::commitAndClose);
        }

        private static ConsumerThrower<DbResource, RuntimeException> handleException(DbResource res,
                                                                                     String response,
                                                                                     AtomicInteger status)
        {
          throw new UnsupportedOperationException("Not supported yet.");
        }
        
        private static class DbResource
        {
          @SafeVarargs
          public static final ConsumerThrower<DbResource, ?>[] actions(
              ConsumerThrower<DbResource, ?>... action)
          {
            return action;
          }
          
          public static void commitAndClose(DbResource dbr)
          {
            throw new UnsupportedOperationException("Not supported yet.");
          }
          
          public final <T extends Throwable> void transaction(
              ConsumerThrower<DbResource, ?>[] action,
              ConsumerThrower<DbResource, T> catcher,
              Consumer<DbResource> finalizer
              ) throws T
          {
            throw new UnsupportedOperationException("Not supported yet.");
          }
        }
        
        @FunctionalInterface
        public static interface ConsumerThrower<A, T extends Throwable>
        {
          public void accept(A arg) throws T;
        }
      }


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: