Skip to content

Commit

Permalink
reverted modified test
Browse files Browse the repository at this point in the history
  • Loading branch information
asotona committed Dec 6, 2023
1 parent 4485a36 commit bacdf48
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/jdk/jdk/classfile/VerifierSelfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;
import java.lang.classfile.ClassHierarchyResolver;
import java.lang.classfile.ClassFile;
import java.lang.classfile.CodeModel;
import java.lang.classfile.MethodModel;
import org.junit.jupiter.api.Test;

class VerifierSelfTest {
Expand All @@ -53,4 +57,30 @@ void testVerify() throws IOException {
}
});
}

@Test
void testFailed() throws IOException {
Path path = FileSystems.getFileSystem(URI.create("jrt:/")).getPath("modules/java.base/java/util/HashMap.class");
var cc = ClassFile.of(ClassFile.ClassHierarchyResolverOption.of(
className -> ClassHierarchyResolver.ClassHierarchyInfo.ofClass(null)));
var classModel = cc.parse(path);
byte[] brokenClassBytes = cc.transform(classModel,
(clb, cle) -> {
if (cle instanceof MethodModel mm) {
clb.transformMethod(mm, (mb, me) -> {
if (me instanceof CodeModel cm) {
mb.withCode(cob -> cm.forEachElement(cob));
}
else
mb.with(me);
});
}
else
clb.with(cle);
});
StringBuilder sb = new StringBuilder();
if (ClassFile.of().verify(brokenClassBytes).isEmpty()) {
throw new AssertionError("expected verification failure");
}
}
}

0 comments on commit bacdf48

Please sign in to comment.