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

java.lang.ClassCastException: com.sun.tools.javac.code.Type$UnionClassType cannot be cast to com.sun.tools.javac.code.Type$IntersectionClass

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u25
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      x86
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java -version
      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

      javac -version
      javac 1.8.0_25


      ADDITIONAL OS VERSION INFORMATION :
      OS X El Capitain ver 10.11.2

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      IntelliJ IDEA 15 CE

      A DESCRIPTION OF THE PROBLEM :
      When I write fizzbuzz programming, error occured.(at compile time. via IntelliJ IDEA 'gradle test')


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      I tried to writing joke programming.

      1. make two classes(FizzException extends RuntimeException implements AutoCloseable, BuzzException extends RuntimeException implements AutoCloseable)
      2. create static method below:

      public static AutoCloseable make(int i) {
              try {
                  // Any processing(no specific feature)
                  throwFizzOrBuzz(i);
              } catch(FizzException | BuzzException e) {e){
                  return (AutoCloseable) e;
              }
              throw new IllegalStateException();
          }

      3.gradle build

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      build success.
      ACTUAL -
      java.lang.ClassCastException: com.sun.tools.javac.code.Type$UnionClassType cannot be cast to com.sun.tools.javac.code.Type$IntersectionClassType

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      14:15:10: Executing external task 'build'...
      コンパイラで例外が発生しました(1.8.0_25)。Bug Paradeで重複がないかをご確認のうえ、Java Developer Connection (http://java.sun.com/webapps/bugreport)でbugの登録をお願いいたします。レポートには、そのプログラムと下記の診断内容を含めてください。ご協力ありがとうございます。
      java.lang.ClassCastException: com.sun.tools.javac.code.Type$UnionClassType cannot be cast to com.sun.tools.javac.code.Type$IntersectionClassType
      at com.sun.tools.javac.code.Types$8.visitClassType(Types.java:1540)
      at com.sun.tools.javac.code.Types$8.visitClassType(Types.java:1497)
      at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:778)
      at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4451)
      at com.sun.tools.javac.code.Types.isCastable(Types.java:1488)
      at com.sun.tools.javac.comp.Check.checkCastable(Check.java:568)
      at com.sun.tools.javac.comp.Check.checkCastable(Check.java:565)
      at com.sun.tools.javac.comp.Attr.visitTypeCast(Attr.java:3126)
      at com.sun.tools.javac.tree.JCTree$JCTypeCast.accept(JCTree.java:1814)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
      at com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1704)
      at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1384)
      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.visitTry(Attr.java:1395)
      at com.sun.tools.javac.tree.JCTree$JCTry.accept(JCTree.java:1173)
      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.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
      at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
      at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:45)
      at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
      at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:101)
      at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:50)
      at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:36)
      at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:34)
      at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
      at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:157)
      at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:137)
      at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:91)
      at sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
      at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:243)
      at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
      at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:230)
      at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
      at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
      at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
      at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
      at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
      at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
      at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
      at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:208)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:186)
      at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:62)
      at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:111)
      at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
      at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
      at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
      at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
      at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
      at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
      at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
      at org.gradle.initialization.DefaultGradleLauncher$6.run(DefaultGradleLauncher.java:174)
      at org.gradle.internal.Factories$1.create(Factories.java:22)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:47)
      at org.gradle.initialization.DefaultGradleLauncher.runBuildOperation(DefaultGradleLauncher.java:189)
      at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:171)
      at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:35)
      at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:104)
      at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:97)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
      at org.gradle.initialization.DefaultGradleLauncher.runRootBuildOperation(DefaultGradleLauncher.java:184)
      at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:97)
      at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
      at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:93)
      at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:50)
      at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
      at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
      at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:27)
      at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:72)
      at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:44)
      at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:49)
      at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
      at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
      at org.gradle.util.Swapper.swap(Swapper.java:38)
      at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66)
      at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:71)
      at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
      at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
      at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
      at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
      at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
      at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
      :compileJava FAILED

      FAILURE: Build failed with an exception.

      * What went wrong:
      Execution failed for task ':compileJava'.
      > Compilation failed; see the compiler error output for details.

      * Try:
      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

      BUILD FAILED

      Total time: 0.419 secs
      Compilation failed; see the compiler error output for details.
      14:15:10: External task execution finished 'build'.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class BuzzException extends RuntimeException implements AutoCloseable{
          @Override
          public void close() {
          }
      }
      public class BuzzException extends RuntimeException implements AutoCloseable{
          @Override
          public void close() {
          }
      }
      public class SUT {
          private SUT(){}
          public static AutoCloseable make(int i) {
              try {
                  throwFizzOrBuzz(i);
              } catch(FizzException | BuzzException e) {
                  return (AutoCloseable) e;
              }
              // unexpected state
              throw new IllegalStateException();
          }
          private static void throwFizzOrBuzz(int i) {
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      refactor multi-catch.

      BEFORE:

       } catch(FizzException | BuzzException e) {
                  return (AutoCloseable) e;
      }


      AFTER:

      } catch(FizzException e){
                  return (AutoCloseable) e;
              }catch(BuzzException e) {
                  return (AutoCloseable) e;
      }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: