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

error: unreported exception Throwable; must be caught or declared to be thrown

    XMLWordPrintable

Details

    • x86_64
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "11.0.4" 2019-07-16
      OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11)
      Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.15.1, JRE 11 Windows 10 amd64-64-Bit Compressed References 20190717_282 (JIT enabled, AOT enabled)
      OpenJ9 - 0f66c6431
      OMR - ec782f26
      JCL - fa49279450 based on jdk-11.0.4+11)

      A DESCRIPTION OF THE PROBLEM :
      Got an error compiling the following class.
      Eclipse Compiler works fine.
      Tested AdoptOpenJDK 11.0.4-hotspot and 11.0.4-openj9

      C:\Shape\workspaces\eclipse\shape-ee8\shape-core-ee8\src\main\java\JavaBugTest.java:31: error: unreported exception Throwable; must be caught or declared to be thrown
                      m2(m1(System::currentTimeMillis));
                           ^


      public class JavaBugTest
      {
      interface Validator<X extends Throwable>
      {
      public void test() throws X;
      }

      // removing U -> compiles
      // returning Object -> compiles
      // returning T -> error!
      // it seems the bug is related to this specific combination of generics
      public static <T, U, X extends Throwable> T m1(Validator<X> v) throws X
          {
      return null;
          }

      public static <T> T m2(T t)
      {
      return null;
      }

      public static void main(String[] args)
      {
      // this one compiles
      m1(System::currentTimeMillis);

      // this one compiles
      m2(JavaBugTest.<Object, Object, RuntimeException> m1(System::currentTimeMillis));

      // error!
      m2(m1(System::currentTimeMillis));
      }
      }

      REGRESSION : Last worked in version 8u221

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile the class

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      compilation successful
      ACTUAL -
      C:\Shape\workspaces\eclipse\shape-ee8\shape-core-ee8\src\main\java\JavaBugTest.java:31: error: unreported exception Throwable; must be caught or declared to be thrown
                      m2(m1(System::currentTimeMillis));
                           ^


      ---------- BEGIN SOURCE ----------
      public class JavaBugTest
      {
      interface Validator<X extends Throwable>
      {
      public void test() throws X;
      }

      // removing U -> compiles
      // returning Object -> compiles
      // returning T -> error!
      // it seems the bug is related to this specific combination of generics
      public static <T, U, X extends Throwable> T m1(Validator<X> v) throws X
          {
      return null;
          }

      public static <T> T m2(T t)
      {
      return null;
      }

      public static void main(String[] args)
      {
      // this one compiles
      m1(System::currentTimeMillis);

      // this one compiles
      m2(JavaBugTest.<Object, Object, RuntimeException> m1(System::currentTimeMillis));

      // error!
      m2(m1(System::currentTimeMillis));
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      explicitly define generic types

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: