[359] Record - Compact Constructor should not have throws clause

Vicente Romero vicente.romero at oracle.com
Tue Feb 11 04:17:28 UTC 2020


On the spec side I agree with Tagir. On the compiler error messages I 
will file an issue to check if we can generate a better error message,

Thanks,
Vicente

On 2/10/20 10:23 PM, Tagir Valeev wrote:
> Hello!
>
> вт, 11 февр. 2020 г., 10:18 Manoj Palat <manoj.palat at in.ibm.com 
> <mailto:manoj.palat at in.ibm.com>>:
>
>     Hi,
>
>     consider
>     record R(){
>              public R throws Exception {}
>     }
>
>      From JLS 14 Sec 8.10.4,
>     A canonical constructor must not have a throws clause.
>
>     Sec 8.10.5 says
>     A compact constructor is a canonical constructor.
>
>     By the above two, it can be inferred that a compact constructor must not have a throws clause. However, there is no explicit mention of this restriction in Sec 8.10.5 [1]
>
>     I think it would good to add this explicitly in the next version of spec (assuming the above is true).
>
>
> This unambiguously follows from the compact constructor declaration 
> production:
>
> /CompactConstructorDeclaration/:
>     { /Annotation/ } { /ConstructorModifier/ } /SimpleTypeName/
>     /ConstructorBody/
>
> No throws at all here. To me, this is enough and no changes are necessary.
>
> With best regards,
> Tagir Valeev.
>
>     [1]http://cr.openjdk.java.net/~gbierman/jep359/jep359-20200115/specs/records-jls.html#jls-8.10.5
>     Regards,
>     Manoj.
>
>     Side Note:
>     To compare, javac throws errors but not this particular error (may be due to error recovery)
>     javac14 --enable-preview --release 14 X.java
>     X.java:2: error: <identifier> expected
>              public R throws Exception {}
>                      ^
>     X.java:2: error: field declaration must be static
>              public R throws Exception {}
>                       ^
>        (consider replacing field with record component)
>     X.java:2: error: invalid method declaration; return type required
>              public R throws Exception {}
>
>



More information about the amber-spec-observers mailing list