Proposal: Start delivering CustomAttribute and UnknownAttribute in CodeModel traversal as CompoundModel

Chen Liang chen.l.liang at oracle.com
Thu Feb 27 20:44:38 UTC 2025


In the recent documentation cleanup for the ClassFile API, I noted there are a few inconsistencies in the handling of attributes on the Code attribute.

  1.
CustomAttribute or UnknownAttribute are not streamed; they can only be discovered via AttributedElement methods.
  2.
While most attributes with LABELS AttributeStability is not directly writable, StackMapTable is; yet it does not recompute the BCI offsets if they are no longer compatible.
  3.
Type annotations in Code are not streamed if debug elements are off; yet CodeBuilder accepts them if users provide them. Other debug elements like local vars are dropped on both sides.

Here are my proposals:

  1.
To make both CustomAttribute and UnknownAttribute CodeElement, and deliver them in traversals, like as if they are class, method, or field elements.
  2.
Inflate and recompute offsets if a bound StackMapTable is written to another code body (such as one with head injection)
  3.
Do nothing for type annotation inconsistency for now. This one is a bit hard to determine the best course of action.

What do you think of my proposals for #1 and #2? FYI I have a pull request open for the proposals at https://github.com/openjdk/jdk/pull/23521, feel free to review.

Also, I understand there is a demand for Labels in user attributes. That topic is a bit more complex, and I wish to address in another mail thread. (Feel free to start a thread about it, too!)

Regards,
Chen Liang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20250227/a0988c2e/attachment-0001.htm>


More information about the classfile-api-dev mailing list