simpleqt opened a new pull request, #543:
URL: https://github.com/apache/commons-bcel/pull/543
`StringRepresentation` has no representation for the attributes of a module
descriptor, so JustIce fails with an internal error instead of reporting them:
```java
VerifierFactory.getVerifier("module-info").doPass2();
// org.apache.bcel.verifier.exc.AssertionViolatedException: INTERNAL ERROR:
// Please adapt 'class org.apache.bcel.verifier.statics.StringRepresentation'
// to deal with objects of class 'class org.apache.bcel.classfile.Module'.
```
`Pass2Verifier` reports every class attribute it does not know through
`StringRepresentation` (`Pass2Verifier.java`, `visitJavaClass`), and the
contract of `StringRepresentation` is that `toString()` never throws for a
`Node` ("A (new StringRepresentation(Node n)).toString() never throws any
exception", `StringRepresentation.java`). The `Module` attribute, the
`ModulePackages` and `ModuleMainClass` attributes, and the `ModuleExports`,
`ModuleOpens`, `ModuleProvides` and `ModuleRequires` entries of a module
descriptor were the remaining class file nodes without a `visit` method, so any
module descriptor ended in that internal error.
### How
The missing `visit` methods are added, following the pattern of the
attribute types that are already handled (`tostring = toString(obj);`):
* `visitModule`, `visitModuleExports`, `visitModuleMainClass`,
`visitModuleOpens`, `visitModulePackages`, `visitModuleProvides`,
`visitModuleRequires`.
With this change `doPass2()` on a module descriptor completes: the `Module`
attribute is reported as an attribute the verifier does not know and the class
file is then rejected with the existing, accurate message "Superclass of
'module-info' missing but not java.lang.Object itself!" (a module descriptor
has no superclass), instead of an internal error.
### Tests
`src/test/java/org/apache/bcel/verifier/statics/StringRepresentationTest.java`
uses the existing `src/test/resources/jpms/java17/commons-io/module-info.class`
fixture:
* the `Module` attribute has a string representation that equals its
`toString()`;
* all of its `requires`, `exports`, `opens` and `provides` entries do too;
* `ModulePackages` and `ModuleMainClass` do too (built on the fixture's
constant pool);
* `doPass2()` on the module descriptor does not throw.
Result with the fix: `Tests run: 4, Failures: 0, Errors: 0, Skipped: 0`.
Without the fix (only the main source change reverted) the same four tests fail
with 1 failure and 3 errors:
```
AssertionViolatedException: INTERNAL ERROR: Please adapt 'class
org.apache.bcel.verifier.statics.StringRepresentation'
to deal with objects of class 'class org.apache.bcel.classfile.Module'.
AssertionViolatedException: INTERNAL ERROR: Please adapt ... 'class
org.apache.bcel.classfile.ModulePackages'.
AssertionViolatedException: INTERNAL ERROR: Please adapt ... 'class
org.apache.bcel.classfile.ModuleRequires'.
AssertionFailedError: Unexpected exception thrown: ... class 'class
org.apache.bcel.classfile.Module'.
```
Full build: `mvn test` -> `Tests run: 3441, Failures: 0, Errors: 0, Skipped:
17`, `mvn checkstyle:check` -> 0 violations.
### AI disclosure
- [x] I used AI to create any part of, or all of, this pull request. Which
AI tool was used to create this pull request, and to what extent did it
contribute?
The change was produced with the DeepSeek Harness (dsv41) coding agent: it
found the failing path by running the verifier over a corpus of javac compiled
class files and module descriptors, wrote the fix and the test, and ran the
build. I reviewed the diff and the test results, and I am responsible for the
contribution. The commit carries the `Assisted-By:` trailer required by
`commons-parent/AGENTS.md`.
--
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]