Skip to content

Commit 267d3a3

Browse files
committed
Merge branch '6.1.x'
# Conflicts: # spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java
2 parents 1784ccb + e235e66 commit 267d3a3

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java

+29-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.instrument.classloading.jboss;
1818

1919
import java.lang.instrument.ClassFileTransformer;
20+
import java.lang.reflect.Constructor;
2021
import java.lang.reflect.Field;
2122
import java.lang.reflect.Method;
2223

@@ -26,22 +27,30 @@
2627
import org.springframework.util.Assert;
2728
import org.springframework.util.ClassUtils;
2829
import org.springframework.util.ReflectionUtils;
30+
import org.springframework.util.function.ThrowingFunction;
2931

3032
/**
3133
* {@link LoadTimeWeaver} implementation for JBoss's instrumentable ClassLoader.
3234
* Thanks to Ales Justin and Marius Bogoevici for the initial prototype.
3335
*
34-
* <p>This weaver supports WildFly 13+.
36+
* <p>This weaver supports WildFly 13-23 (DelegatingClassFileTransformer) as well as
37+
* WildFly 24+ (DelegatingClassTransformer), as of Spring Framework 6.1.15.
3538
*
3639
* @author Costin Leau
3740
* @author Juergen Hoeller
3841
* @since 3.0
3942
*/
4043
public class JBossLoadTimeWeaver implements LoadTimeWeaver {
4144

42-
private static final String DELEGATING_TRANSFORMER_CLASS_NAME =
45+
private static final String LEGACY_DELEGATING_TRANSFORMER_CLASS_NAME =
4346
"org.jboss.as.server.deployment.module.DelegatingClassFileTransformer";
4447

48+
private static final String DELEGATING_TRANSFORMER_CLASS_NAME =
49+
"org.jboss.as.server.deployment.module.DelegatingClassTransformer";
50+
51+
private static final String CLASS_TRANSFORMER_CLASS_NAME =
52+
"org.jboss.modules.ClassTransformer";
53+
4554
private static final String WRAPPER_TRANSFORMER_CLASS_NAME =
4655
"org.jboss.modules.JLIClassTransformer";
4756

@@ -52,6 +61,8 @@ public class JBossLoadTimeWeaver implements LoadTimeWeaver {
5261

5362
private final Method addTransformer;
5463

64+
private final ThrowingFunction<Object, Object> adaptTransformer;
65+
5566

5667
/**
5768
* Create a new instance of the {@link JBossLoadTimeWeaver} class using
@@ -90,18 +101,29 @@ public JBossLoadTimeWeaver(@Nullable ClassLoader classLoader) {
90101
wrappedTransformer.setAccessible(true);
91102
suggestedTransformer = wrappedTransformer.get(suggestedTransformer);
92103
}
93-
if (!suggestedTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) {
104+
105+
Class<?> transformerType = ClassFileTransformer.class;
106+
if (suggestedTransformer.getClass().getName().equals(LEGACY_DELEGATING_TRANSFORMER_CLASS_NAME)) {
107+
this.adaptTransformer = (t -> t);
108+
}
109+
else if (suggestedTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) {
110+
transformerType = classLoader.loadClass(CLASS_TRANSFORMER_CLASS_NAME);
111+
Constructor<?> adaptedTransformer = classLoader.loadClass(WRAPPER_TRANSFORMER_CLASS_NAME)
112+
.getConstructor(ClassFileTransformer.class);
113+
this.adaptTransformer = adaptedTransformer::newInstance;
114+
}
115+
else {
94116
throw new IllegalStateException(
95-
"Transformer not of the expected type DelegatingClassFileTransformer: " +
117+
"Transformer not of expected type DelegatingClass(File)Transformer: " +
96118
suggestedTransformer.getClass().getName());
97119
}
98120
this.delegatingTransformer = suggestedTransformer;
99121

100122
Method addTransformer = ReflectionUtils.findMethod(this.delegatingTransformer.getClass(),
101-
"addTransformer", ClassFileTransformer.class);
123+
"addTransformer", transformerType);
102124
if (addTransformer == null) {
103125
throw new IllegalArgumentException(
104-
"Could not find 'addTransformer' method on JBoss DelegatingClassFileTransformer: " +
126+
"Could not find 'addTransformer' method on JBoss DelegatingClass(File)Transformer: " +
105127
this.delegatingTransformer.getClass().getName());
106128
}
107129
addTransformer.setAccessible(true);
@@ -116,7 +138,7 @@ public JBossLoadTimeWeaver(@Nullable ClassLoader classLoader) {
116138
@Override
117139
public void addTransformer(ClassFileTransformer transformer) {
118140
try {
119-
this.addTransformer.invoke(this.delegatingTransformer, transformer);
141+
this.addTransformer.invoke(this.delegatingTransformer, this.adaptTransformer.apply(transformer));
120142
}
121143
catch (Throwable ex) {
122144
throw new IllegalStateException("Could not add transformer on JBoss ClassLoader: " + this.classLoader, ex);

spring-core/src/main/java/org/springframework/util/function/ThrowingBiFunction.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,17 +85,14 @@ default R apply(T t, U u, BiFunction<String, Exception, RuntimeException> except
8585
*/
8686
default ThrowingBiFunction<T, U, R> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) {
8787
return new ThrowingBiFunction<>() {
88-
8988
@Override
9089
public R applyWithException(T t, U u) throws Exception {
9190
return ThrowingBiFunction.this.applyWithException(t, u);
9291
}
93-
9492
@Override
9593
public R apply(T t, U u) {
9694
return apply(t, u, exceptionWrapper);
9795
}
98-
9996
};
10097
}
10198

spring-core/src/main/java/org/springframework/util/function/ThrowingConsumer.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,17 +77,14 @@ default void accept(T t, BiFunction<String, Exception, RuntimeException> excepti
7777
*/
7878
default ThrowingConsumer<T> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) {
7979
return new ThrowingConsumer<>() {
80-
8180
@Override
8281
public void acceptWithException(T t) throws Exception {
8382
ThrowingConsumer.this.acceptWithException(t);
8483
}
85-
8684
@Override
8785
public void accept(T t) {
8886
accept(t, exceptionWrapper);
8987
}
90-
9188
};
9289
}
9390

spring-core/src/main/java/org/springframework/util/function/ThrowingFunction.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,17 +80,14 @@ default R apply(T t, BiFunction<String, Exception, RuntimeException> exceptionWr
8080
*/
8181
default ThrowingFunction<T, R> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) {
8282
return new ThrowingFunction<>() {
83-
8483
@Override
8584
public R applyWithException(T t) throws Exception {
8685
return ThrowingFunction.this.applyWithException(t);
8786
}
88-
8987
@Override
9088
public R apply(T t) {
9189
return apply(t, exceptionWrapper);
9290
}
93-
9491
};
9592
}
9693

0 commit comments

Comments
 (0)