8279921: Dump the .class file in jlink debug mode for any failure during transform() of a plugin
Reviewed-by: mchung
This commit is contained in:
parent
1022cbdf98
commit
e683d4ac8d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2022, 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
|
||||
@ -36,6 +36,7 @@ import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||
import jdk.tools.jlink.plugin.ResourcePoolEntry;
|
||||
|
||||
public abstract class AbstractPlugin implements Plugin {
|
||||
|
||||
@ -83,16 +84,31 @@ public abstract class AbstractPlugin implements Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
ClassReader newClassReader(String path, ResourcePoolEntry resource) {
|
||||
byte[] content = resource.contentBytes();
|
||||
try {
|
||||
return new ClassReader(content);
|
||||
} catch (Exception e) {
|
||||
if (JlinkTask.DEBUG) {
|
||||
System.err.printf("Failed to parse class file: %s from resource of type %s\n", path,
|
||||
resource.getClass().getName());
|
||||
e.printStackTrace();
|
||||
dumpClassFile(path, content);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected ClassReader newClassReader(String path, byte[] buf) {
|
||||
try {
|
||||
return new ClassReader(buf);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
} catch (Exception e) {
|
||||
if (JlinkTask.DEBUG) {
|
||||
System.err.printf("Failed to parse class file: %s\n", path);
|
||||
iae.printStackTrace();
|
||||
e.printStackTrace();
|
||||
dumpClassFile(path, buf);
|
||||
}
|
||||
throw iae;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public final class StripJavaDebugAttributesPlugin extends AbstractPlugin {
|
||||
if (path.endsWith("module-info.class")) {
|
||||
// XXX. Do we have debug info? Is Asm ready for module-info?
|
||||
} else {
|
||||
ClassReader reader = newClassReader(path, resource.contentBytes());
|
||||
ClassReader reader = newClassReader(path, resource);
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
reader.accept(writer, ClassReader.SKIP_DEBUG);
|
||||
byte[] content = writer.toByteArray();
|
||||
|
Loading…
Reference in New Issue
Block a user