agamal026 commented on PR #540: URL: https://github.com/apache/commons-bcel/pull/540#issuecomment-6347912369
You're right; BootstrapMethod is not the only affected class. I selected it as a bounded part of BCEL-238: its arguments are a primitive `int[]`, the array-taking constructor delegates to one setter, and there is one getter plus a direct serialization result in `dump()`. This lets the change cover input and output ownership together without choosing how deeply to copy mutable element objects. The recent copy-independence fix in #516 also prompted inspection of this class, but that fix does not establish a copying policy for its accessors. A wider change needs contract distinctions. [`JavaClass.getMethods()`](https://github.com/apache/commons-bcel/blob/0d7c17fb365e4be8e3b66018548e7ebbda0e9507/src/main/java/org/apache/bcel/classfile/JavaClass.java#L664-L671) returns a live array: [Peephole](https://github.com/apache/commons-bcel/blob/0d7c17fb365e4be8e3b66018548e7ebbda0e9507/src/examples/Peephole.java#L38-L58) and [Helloify](https://github.com/apache/commons-bcel/blob/0d7c17fb365e4be8e3b66018548e7ebbda0e9507/src/examples/Helloify.java#L118-L127) replace elements and dump the class without calling `setMethods()`. [`Code(Code)`](https://github.com/apache/commons-bcel/blob/0d7c17fb365e4be8e3b66018548e7ebbda0e9507/src/main/java/org/apache/bcel/classfile/Code.java#L72-L81) explicitly documents shared references. Cloning all array boundaries would change those behaviors. The selection was a limited ownership change, not a BootstrapMethod-specific user failure or a claim that the other APIs are safe. This PR also changes the existing live-array behavior: callers must use `setBootstrapArguments(...)` to apply edits. The regression tests show the aliasing and serialized-output difference; they do not settle whether that compatibility change is the preferred project policy. Would you prefer this as a scoped increment under BCEL-238, or should we first establish which related APIs should return copies versus live arrays? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
