mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-04 12:08:36 +00:00
8349099: java/awt/Headless/HeadlessMalfunctionTest.java fails on CI with Compilation error
Reviewed-by: aivanov, sgehwolf, prr
This commit is contained in:
parent
64464eab62
commit
1dd9cf1018
@ -462,7 +462,6 @@ java/awt/PopupMenu/PopupMenuLocation.java 8259913,8315878 windows-all,macosx-aar
|
||||
java/awt/GridLayout/ComponentPreferredSize/ComponentPreferredSize.java 8238720,8324782 windows-all,macosx-all
|
||||
java/awt/GridLayout/ChangeGridSize/ChangeGridSize.java 8238720,8324782 windows-all,macosx-all
|
||||
java/awt/event/MouseEvent/FrameMouseEventAbsoluteCoordsTest/FrameMouseEventAbsoluteCoordsTest.java 8238720 windows-all
|
||||
java/awt/Headless/HeadlessMalfunctionTest.java 8349099 generic-all
|
||||
|
||||
# Several tests which fail sometimes on macos11
|
||||
java/awt/Window/MainKeyWindowTest/TestMainKeyWindow.java 8265985 macosx-all
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -20,12 +20,9 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||
import jdk.internal.org.objectweb.asm.ClassVisitor;
|
||||
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||
import jdk.internal.org.objectweb.asm.MethodVisitor;
|
||||
import jdk.internal.org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.MethodModel;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.security.ProtectionDomain;
|
||||
@ -37,34 +34,31 @@ public class HeadlessMalfunctionAgent {
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation inst) {
|
||||
inst.addTransformer(new ClassFileTransformer() {
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
|
||||
ProtectionDomain pd, byte[] cb) {
|
||||
if ("java/awt/GraphicsEnvironment".equals(className)) {
|
||||
System.out.println("Transforming java.awt.GraphicsEnvironment.");
|
||||
try {
|
||||
final ClassReader cr = new ClassReader(cb);
|
||||
final ClassWriter cw = new ClassWriter(cr, 0);
|
||||
cr.accept(new ClassVisitor(Opcodes.ASM9, cw) {
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature,
|
||||
String[] exceptions) {
|
||||
if ("isHeadless".equals(name) && "()Z".equals(descriptor)) {
|
||||
System.out.println("isHeadless removed from java.awt.GraphicsEnvironment.");
|
||||
// WHACK! Remove the isHeadless method.
|
||||
return null;
|
||||
}
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
}, 0);
|
||||
return cw.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public byte[] transform(ClassLoader loader,
|
||||
String className,
|
||||
Class<?> classBeingRedefined,
|
||||
ProtectionDomain pd,
|
||||
byte[] cb) {
|
||||
if (!"java/awt/GraphicsEnvironment".equals(className)) {
|
||||
return null;
|
||||
}
|
||||
System.out.println("Transforming java.awt.GraphicsEnvironment.");
|
||||
try {
|
||||
return ClassFile.of().transformClass(ClassFile.of().parse(cb), (classBuilder, element) -> {
|
||||
if (element instanceof MethodModel method) {
|
||||
if ("isHeadless".equals(method.methodName().stringValue()) &&
|
||||
"()Z".equals(method.methodType().stringValue())) {
|
||||
System.out.println("isHeadless removed from java.awt.GraphicsEnvironment.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
classBuilder.with(element);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -33,12 +33,11 @@ import java.nio.file.Path;
|
||||
* @bug 8336382
|
||||
* @summary Test that in absence of isHeadless method, the JDK throws a meaningful error message.
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.org.objectweb.asm
|
||||
* @requires os.family == "linux"
|
||||
* @build HeadlessMalfunctionAgent
|
||||
* @run driver jdk.test.lib.helpers.ClassFileInstaller
|
||||
* HeadlessMalfunctionAgent
|
||||
* HeadlessMalfunctionAgent$1
|
||||
* HeadlessMalfunctionAgent$1$1
|
||||
* @run driver HeadlessMalfunctionTest
|
||||
*/
|
||||
public class HeadlessMalfunctionTest {
|
||||
@ -49,19 +48,20 @@ public class HeadlessMalfunctionTest {
|
||||
final ProcessBuilder pbJar = new ProcessBuilder()
|
||||
.command(JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF", "agent.jar",
|
||||
"HeadlessMalfunctionAgent.class",
|
||||
"HeadlessMalfunctionAgent$1.class",
|
||||
"HeadlessMalfunctionAgent$1$1.class");
|
||||
"HeadlessMalfunctionAgent$1.class");
|
||||
ProcessTools.executeProcess(pbJar).shouldHaveExitValue(0);
|
||||
|
||||
// Run test
|
||||
final ProcessBuilder pbJava = ProcessTools.createTestJavaProcessBuilder(
|
||||
"--add-opens",
|
||||
"java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED",
|
||||
"-javaagent:agent.jar",
|
||||
"HeadlessMalfunctionTest$Runner"
|
||||
);
|
||||
final OutputAnalyzer output = ProcessTools.executeProcess(pbJava);
|
||||
// Unpatched JDK logs: "FATAL ERROR in native method: Could not allocate library name"
|
||||
// Patched should mention that isHeadless is missing, log message differs between OSes;
|
||||
// e.g. LWCToolkit toolkit path on MacOS and Win32GraphicsEnvironment code path on Windows
|
||||
// logs "java.lang.NoSuchMethodError: 'boolean java.awt.GraphicsEnvironment.isHeadless()'",
|
||||
// whereas Linux logs "FATAL ERROR in native method: GetStaticMethodID isHeadless failed"
|
||||
output.shouldContain("FATAL ERROR in native method: GetStaticMethodID isHeadless failed");
|
||||
output.shouldNotHaveExitValue(0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user