RFR: JDK-8312418: Add Elements.getEnumConstantBody [v5]

Jonathan Gibbons jjg at openjdk.org
Thu Aug 24 22:26:17 UTC 2023


On Thu, 24 Aug 2023 22:15:44 GMT, Pavel Rappo <prappo at openjdk.org> wrote:

>> Joe Darcy has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Refactor as suggested by jjg.
>
> src/java.compiler/share/classes/javax/lang/model/util/Elements.java line 779:
> 
>> 777:     default TypeElement getEnumConstantBody(VariableElement enumConstant) {
>> 778:         switch(enumConstant.getKind()) {
>> 779:         case ENUM_CONSTANT -> throw new UnsupportedOperationException();
> 
> Hm... Most retrofitted methods in this API return null or false, not throw UnsupportedOperationException. The only other exception seems to be Elements.getFileObjectOf. Is this the new approach, or it just does make more sense for these two particular methods?

I think it depends whether a `null` result is permitted by the specification of the method.  For this method, while `null` would be the correct result most of the time, it is exactly the wrong result when it is most interesting, and so a non-exception result would be misleading.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14939#discussion_r1304931340


More information about the compiler-dev mailing list