RFR: 8313452: Improve Classfile API attributes handling safety [v3]
Adam Sotona
asotona at openjdk.org
Wed Sep 6 15:03:26 UTC 2023
On Wed, 6 Sep 2023 13:54:28 GMT, ExE Boss <duke at openjdk.org> wrote:
>> Adam Sotona has updated the pull request incrementally with one additional commit since the last revision:
>>
>> magic moved to Util::isAttributeAllowed and fixed possible NPE
>
> src/java.base/share/classes/jdk/internal/classfile/impl/AbstractDirectBuilder.java line 59:
>
>> 57: if (a instanceof UnboundAttribute ||
>> 58: 5 - a.attributeMapper().attributeStability().ordinal()
>> 59: > context.attributesProcessingOption().ordinal()) {
>
> Maybe extract the `5 - a.attributeMapper().attributeStability().ordinal() > context.attributesProcessingOption().ordinal()` check into a helper method, as the current expression is too noisy:
>
> import jdk.internal.classfile.AttributeMapper.AttributeStability;
> import jdk.internal.classfile.Classfile.AttributesProcessingOption;
>
> private static final int ATTRIBUTE_STABILITY_COUNT = AttributeStability.values().length;
> public static boolean isAttributeAllowed(
> final AttributeStability stability,
> final AttributesProcessingOption processingOption
> ) {
> return ATTRIBUTE_STABILITY_COUNT - stability.ordinal() > processingOption.ordinal();
> }
>
>
> Also, the magic number should probably be replaced with a constant storing the value of `AttributeStability.values().length`.
Fixed, thanks!
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15101#discussion_r1317422600
More information about the core-libs-dev
mailing list