-
CSR
-
Resolution: Approved
-
P3
-
source
-
minimal
-
Impact of the API change is none as the ClassFile API (Preview) has not been released yet.
-
Java API
-
SE
Summary
ClassModel::verify
is inconsistent with the rest of the ClassFile API
Problem
ClassFile API ClassModel::verify
accepts ClassHierarchyResolver
as an optional argument and does not respect ClassFile.ClassHierarchyResolverOption
of the actual context.
Parsing, building and transformation take options from the actual ClassFile
context and verification should follow the same API pattern.
Solution
Move verify
methods from ClassModel
to the top level ClassFile
.
Specification
src/java.base/share/classes/java/lang/classfile/ClassFile.java
+ /**
+ * Verify a classfile. Any verification errors found will be returned.
+ * @param model the class model to verify
+ * @return a list of verification errors, or an empty list if no errors are
+ * found
+ */
+ List<VerifyError> verify(ClassModel model);
+
+ /**
+ * Verify a classfile. Any verification errors found will be returned.
+ * @param bytes the classfile bytes to verify
+ * @return a list of verification errors, or an empty list if no errors are
+ * found
+ */
+ List<VerifyError> verify(byte[] bytes);
+
+ /**
+ * Verify a classfile. Any verification errors found will be returned.
+ * @param path the classfile path to verify
+ * @return a list of verification errors, or an empty list if no errors are
+ * found
+ * @throws java.io.IOException if an I/O error occurs
+ */
+ default List<VerifyError> verify(Path path) throws IOException {
+ return verify(Files.readAllBytes(path));
+ }
+
src/java.base/share/classes/java/lang/classfile/ClassModel.java
- /**
- * Verify this classfile. Any verification errors found will be returned.
- *
- * @param debugOutput handler to receive debug information
- * @return a list of verification errors, or an empty list if no errors are
- * found
- */
- default List<VerifyError> verify(Consumer<String> debugOutput) {
- return VerifierImpl.verify(this, debugOutput);
- }
- /**
- * Verify this classfile. Any verification errors found will be returned.
- *
- * @param debugOutput handler to receive debug information
- * @param classHierarchyResolver class hierarchy resolver to provide
- * additional information about the class hierarchy
- * @return a list of verification errors, or an empty list if no errors are
- * found
- */
- default List<VerifyError> verify(ClassHierarchyResolver classHierarchyResolver,
- Consumer<String> debugOutput) {
- return VerifierImpl.verify(this, classHierarchyResolver, debugOutput);
- }
src/java.base/share/classes/java/lang/classfile/package-info.java
- * More complex verification of a classfile can be achieved by explicit invocation
- * of {@link java.lang.classfile.ClassModel#verify}.
+ * More complex verification of a classfile can be achieved by invocation of
+ * {@link java.lang.classfile.ClassFile#verify}.
- csr of
-
JDK-8321248 ClassFile API ClassModel::verify is inconsistent with the rest of the API
- Closed