Skip to content

Commit 8400633

Browse files
committed
Fixes from prev revisions
Fix OWB test on jbr17 - allow MAJOR_VERSION overriding (cherry picked from commit 8724444) Added missing JDK versions in ClassFile (cherry picked from commit 6fa6ee0) fix #269 - using addSuperclassName() (cherry picked from commit 0e3fa16) Fix class not found excception in weld plugin Fix problems with unknown OuterClass in classloader from intrumentation callback (cherry picked from commit c90337c)
1 parent 7aad944 commit 8400633

File tree

6 files changed

+117
-4
lines changed

6 files changed

+117
-4
lines changed

hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/CtArray.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public CtClass getSuperclass() throws NotFoundException
103103
return pool.get(javaLangObject);
104104
}
105105

106+
public String getSuperclassName() throws NotFoundException
107+
{
108+
CtClass superclass = getSuperclass();
109+
return superclass != null ? superclass.getName() : null;
110+
}
111+
106112
@Override
107113
public CtMethod[] getMethods()
108114
{

hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/CtClass.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ public CtClass getSuperclass() throws NotFoundException {
725725
return null;
726726
}
727727

728+
public String getSuperclassName() throws NotFoundException {
729+
return null;
730+
}
731+
728732
/**
729733
* Changes a super class unless this object represents an interface.
730734
* The new super class must be compatible with the old one; for example,
@@ -783,6 +787,16 @@ public CtClass getDeclaringClass() throws NotFoundException {
783787
return null;
784788
}
785789

790+
/**
791+
* Checks if ctClass is inner class.
792+
*
793+
* @return true, if is inner class
794+
* @throws NotFoundException the not found exception
795+
*/
796+
public boolean isInnerClass() throws NotFoundException {
797+
return false;
798+
}
799+
786800
/**
787801
* Returns the immediately enclosing method of this class.
788802
* This method works only with JDK 1.5 or later.

hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/CtClassType.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,11 @@ public CtClass getSuperclass() throws NotFoundException {
839839
return classPool.get(supername);
840840
}
841841

842+
@Override
843+
public String getSuperclassName() throws NotFoundException {
844+
return getClassFile2().getSuperclass();
845+
}
846+
842847
@Override
843848
public void setSuperclass(CtClass clazz) throws CannotCompileException {
844849
checkModify();
@@ -910,6 +915,33 @@ public CtClass getDeclaringClass() throws NotFoundException {
910915
return null;
911916
}
912917

918+
public boolean isInnerClass() throws NotFoundException {
919+
ClassFile cf = getClassFile2();
920+
InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(
921+
InnerClassesAttribute.tag);
922+
if (ica == null)
923+
return false;
924+
925+
String name = getName();
926+
int n = ica.tableLength();
927+
for (int i = 0; i < n; ++i)
928+
if (name.equals(ica.innerClass(i))) {
929+
String outName = ica.outerClass(i);
930+
if (outName != null)
931+
return true;
932+
else {
933+
// maybe anonymous or local class.
934+
EnclosingMethodAttribute ema
935+
= (EnclosingMethodAttribute)cf.getAttribute(
936+
EnclosingMethodAttribute.tag);
937+
if (ema != null)
938+
return true;
939+
}
940+
}
941+
942+
return false;
943+
}
944+
913945
@Override
914946
public CtBehavior getEnclosingBehavior() throws NotFoundException
915947
{

hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/ClassFile.java

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,42 @@ public final class ClassFile {
136136
*/
137137
public static final int JAVA_11 = 55;
138138

139+
/**
140+
* The major version number of class files
141+
* for JDK 12.
142+
*/
143+
public static final int JAVA_12 = 56;
144+
145+
/**
146+
* The major version number of class files
147+
* for JDK 13.
148+
*/
149+
public static final int JAVA_13 = 57;
150+
151+
/**
152+
* The major version number of class files
153+
* for JDK 14.
154+
*/
155+
public static final int JAVA_14 = 58;
156+
157+
/**
158+
* The major version number of class files
159+
* for JDK 15.
160+
*/
161+
public static final int JAVA_15 = 59;
162+
163+
/**
164+
* The major version number of class files
165+
* for JDK 16.
166+
*/
167+
public static final int JAVA_16 = 60;
168+
169+
/**
170+
* The major version number of class files
171+
* for JDK 17.
172+
*/
173+
public static final int JAVA_17 = 61;
174+
139175
/**
140176
* The major version number of class files created
141177
* from scratch. The default value is 47 (JDK 1.3).
@@ -153,8 +189,20 @@ public final class ClassFile {
153189
* if the JVM supports <code>java.util.List.copyOf(Collection)</code>.
154190
* It is 55 (JDK 11)
155191
* if the JVM supports <code>java.util.Optional.isEmpty()</code>.
156-
*/
157-
public static final int MAJOR_VERSION;
192+
* It is 56 (JDK 12)
193+
* if the JVM supports <code>com.sun.source.tree.CaseTree.getExpressions()</code>.
194+
* It is 57 (JDK 13)
195+
* if the JVM supports <code>com.sun.source.tree.YieldTree</code>.
196+
* It is 58 (JDK 14)
197+
* if the JVM supports <code>com.sun.management.OperatingSystemMXBean.getFreeMemorySize()</code>.
198+
* It is 59 (JDK 15)
199+
* if the JVM supports <code>java.security.interfaces.EdECPublicKey</code>.
200+
* It is 60 (JDK 16)
201+
* if the JVM supports <code>com.sun.source.tree.PatternTree</code>.
202+
* It is 61 (JDK 17)
203+
* if the JVM supports <code>java.util.random.RandomGenerator</code>.
204+
*/
205+
public static int MAJOR_VERSION;
158206

159207
static {
160208
int ver = JAVA_3;
@@ -173,8 +221,19 @@ public final class ClassFile {
173221
ver = JAVA_10;
174222
Class.forName("java.util.Optional").getMethod("isEmpty");
175223
ver = JAVA_11;
176-
}
177-
catch (Throwable t) {}
224+
Class.forName("com.sun.source.tree.CaseTree").getMethod("getExpressions");
225+
ver = JAVA_12;
226+
Class.forName("com.sun.source.tree.YieldTree");
227+
ver = JAVA_13;
228+
Class.forName("com.sun.management.OperatingSystemMXBean").getMethod("getFreeMemorySize");
229+
ver = JAVA_14;
230+
Class.forName("java.security.interfaces.EdECPublicKey");
231+
ver = JAVA_15;
232+
Class.forName("com.sun.source.tree.PatternTree");
233+
ver = JAVA_16;
234+
Class.forName("java.util.random.RandomGenerator");
235+
ver = JAVA_17;
236+
} catch (Throwable t) {}
178237
MAJOR_VERSION = ver;
179238
}
180239

hotswap-agent-parent/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
338338
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
339339
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
340+
<maven.compiler.release>11</maven.compiler.release>
340341
</properties>
341342

342343

plugin/hotswap-agent-owb-plugin/src/test/java/org/hotswap/agent/plugin/owb/OwbPluginTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public void hotswapPrototypeTestNotFailWhenHoldingInstanceBecauseSingletonInject
206206
@Test
207207
public void newBeanClassIsManagedBeanReRunTestOnlyAfterMvnClean() throws Exception {
208208
try {
209+
ClassFile.MAJOR_VERSION = ClassFile.JAVA_11; // hack, ASM9 does not support java17 (owb 2.0.26)
209210
OwbPlugin.isTestEnvironment = true;
210211
Class<?> clazz = getClass();
211212
String path = clazz.getResource(clazz.getSimpleName() + ".class")

0 commit comments

Comments
 (0)