-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
17, 18
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Found and verified in Java 18
A DESCRIPTION OF THE PROBLEM :
I believe this is an error in the language definition. The record definition allows compact constructors, which may contain code that throws an exception (which may be a checked exception). But there is nowhere to place the throws clause for that exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a record class. Create a compact constructor for that class. Add a throw statement for a checked exception. The compiler will tell you that you need a throws clause. If you add a throws clause the compiler will tell you that you are missing an open brace or that the throws clause is not permitted
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected a clean compilation.
ACTUAL -
Code could not be compiled.
---------- BEGIN SOURCE ----------
public class NewMain
{
public static void main(String[] args)
{
// TODO code application logic here
}
record Abc(int xyz)
{
Abc
{
throw new Exception)();
}
}
}
---------- END SOURCE ----------
FREQUENCY : always
Found and verified in Java 18
A DESCRIPTION OF THE PROBLEM :
I believe this is an error in the language definition. The record definition allows compact constructors, which may contain code that throws an exception (which may be a checked exception). But there is nowhere to place the throws clause for that exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a record class. Create a compact constructor for that class. Add a throw statement for a checked exception. The compiler will tell you that you need a throws clause. If you add a throws clause the compiler will tell you that you are missing an open brace or that the throws clause is not permitted
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected a clean compilation.
ACTUAL -
Code could not be compiled.
---------- BEGIN SOURCE ----------
public class NewMain
{
public static void main(String[] args)
{
// TODO code application logic here
}
record Abc(int xyz)
{
Abc
{
throw new Exception)();
}
}
}
---------- END SOURCE ----------
FREQUENCY : always