Minor issue with stack map generator and generics

David Lloyd david.lloyd at redhat.com
Mon Aug 28 16:50:35 UTC 2023


I've been doing more experimenting with this API and ran across a minor
issue. The way the stack map generator API is presently structured, it
seems difficult to "get-or-generate".

For example, I thought to find the stack map for a method, or otherwise
generate it if it did not exist, so my code looked something like this
(structured for readability):

    MethodModel mm = ....;
    Optional<StackMapAttribute> optAttr =
mm.findAttribute(Attributes.STACK_MAP_TABLE);
    StackMapAttribute sma = optAttr.orElseGet(() -> new
StackMapGenerator(...).stackMapTableAttribute());

But this fails because `StackMapGenerator.stackMapTableAttribute()` returns
an `Attribute<? extends StackMapAttribute>` instead of just
`StackMapAttribute`. This method returns an anonymous subclass of
`AdHocAttribute`; could it instead be changed to an inner class which also
implements `StackMapAttribute`? I think this might be more correct as well
because the type argument of `Attribute` seems like it was intended to be a
self-type, and if so, these direct anonymous subclasses (and there are a
few of them) seem to violate that intention.

-- 
- DML • he/him
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20230828/e1216e2d/attachment.htm>


More information about the classfile-api-dev mailing list