Skip to content

Commit 4f26942

Browse files
HzjNeverStop致节
authored andcommitted
Update springboot 3.2.0 (sofastack#1266)
* update version to 4.2.0-SNAPSHOT * add ci for jdk 21 * update springboot to 3.2.0 * update springboot 3.2.0 * update jacoco 0.8.11 * update sofa ark 3.0.1 * update springcloud 2023.0.0 * update asm 9.5 * update sprigncloud 2023.0.0 * fix ut * fix ut --------- Co-authored-by: 致节 <[email protected]>
1 parent c5147ed commit 4f26942

File tree

6 files changed

+287
-24
lines changed

6 files changed

+287
-24
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>org.springframework.boot</groupId>
2626
<artifactId>spring-boot-starter-parent</artifactId>
27-
<version>3.1.5</version>
27+
<version>3.2.0</version>
2828
</parent>
2929

3030
<groupId>com.alipay.sofa</groupId>
@@ -37,7 +37,7 @@
3737
<properties>
3838
<revision>4.2.0-SNAPSHOT</revision>
3939
<sofa.boot.version>${revision}</sofa.boot.version>
40-
<spring.boot.version>3.1.5</spring.boot.version>
40+
<spring.boot.version>3.2.0</spring.boot.version>
4141
<!--project-->
4242
<java.version>17</java.version>
4343
<project.encoding>UTF-8</project.encoding>

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spring/ServiceBeanFactoryPostProcessor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.alipay.sofa.runtime.spi.service.BindingConverter;
3636
import com.alipay.sofa.runtime.spi.service.BindingConverterContext;
3737
import com.alipay.sofa.runtime.spi.service.BindingConverterFactory;
38+
import com.alipay.sofa.runtime.spring.bean.LocalVariableTableParameterNameDiscoverer;
3839
import com.alipay.sofa.runtime.spring.bean.SofaBeanNameGenerator;
3940
import com.alipay.sofa.runtime.spring.bean.SofaParameterNameDiscoverer;
4041
import com.alipay.sofa.runtime.spring.factory.ReferenceFactoryBean;
@@ -60,8 +61,10 @@
6061
import org.springframework.context.annotation.Bean;
6162
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
6263
import org.springframework.core.DefaultParameterNameDiscoverer;
64+
import org.springframework.core.NativeDetector;
6365
import org.springframework.core.Ordered;
6466
import org.springframework.core.ParameterNameDiscoverer;
67+
import org.springframework.core.PrioritizedParameterNameDiscoverer;
6568
import org.springframework.core.annotation.AnnotatedElementUtils;
6669
import org.springframework.core.type.MethodMetadata;
6770
import org.springframework.core.type.StandardMethodMetadata;
@@ -113,6 +116,11 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
113116
if (parameterNameDiscoverer == null) {
114117
parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
115118
}
119+
// keep compatible for second jars
120+
if (parameterNameDiscoverer instanceof PrioritizedParameterNameDiscoverer prioritizedParameterNameDiscoverer
121+
&& !NativeDetector.inNativeImage()) {
122+
prioritizedParameterNameDiscoverer.addDiscoverer(new LocalVariableTableParameterNameDiscoverer());
123+
}
116124
((AbstractAutowireCapableBeanFactory) beanFactory)
117125
.setParameterNameDiscoverer(new SofaParameterNameDiscoverer(parameterNameDiscoverer, referenceAnnotationWrapper));
118126
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alipay.sofa.runtime.spring.bean;
18+
19+
import org.apache.commons.logging.Log;
20+
import org.apache.commons.logging.LogFactory;
21+
import org.springframework.asm.ClassReader;
22+
import org.springframework.asm.ClassVisitor;
23+
import org.springframework.asm.Label;
24+
import org.springframework.asm.MethodVisitor;
25+
import org.springframework.asm.Opcodes;
26+
import org.springframework.asm.SpringAsmInfo;
27+
import org.springframework.asm.Type;
28+
import org.springframework.core.BridgeMethodResolver;
29+
import org.springframework.core.ParameterNameDiscoverer;
30+
import org.springframework.lang.Nullable;
31+
import org.springframework.util.ClassUtils;
32+
33+
import java.io.IOException;
34+
import java.io.InputStream;
35+
import java.lang.reflect.Constructor;
36+
import java.lang.reflect.Executable;
37+
import java.lang.reflect.Method;
38+
import java.util.Collections;
39+
import java.util.Map;
40+
import java.util.concurrent.ConcurrentHashMap;
41+
42+
/**
43+
* Deprecate in spring, fork codes for compatible
44+
*/
45+
@Deprecated
46+
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
47+
48+
private static final Log logger = LogFactory
49+
.getLog(LocalVariableTableParameterNameDiscoverer.class);
50+
51+
// marker object for classes that do not have any debug info
52+
private static final Map<Executable, String[]> NO_DEBUG_INFO_MAP = Collections
53+
.emptyMap();
54+
55+
// the cache uses a nested index (value is a map) to keep the top level cache relatively small in size
56+
private final Map<Class<?>, Map<Executable, String[]>> parameterNamesCache = new ConcurrentHashMap<>(
57+
32);
58+
59+
@Override
60+
@Nullable
61+
public String[] getParameterNames(Method method) {
62+
Method originalMethod = BridgeMethodResolver.findBridgedMethod(method);
63+
return doGetParameterNames(originalMethod);
64+
}
65+
66+
@Override
67+
@Nullable
68+
public String[] getParameterNames(Constructor<?> ctor) {
69+
return doGetParameterNames(ctor);
70+
}
71+
72+
@Nullable
73+
private String[] doGetParameterNames(Executable executable) {
74+
Class<?> declaringClass = executable.getDeclaringClass();
75+
Map<Executable, String[]> map = this.parameterNamesCache.computeIfAbsent(declaringClass, this::inspectClass);
76+
return (map != NO_DEBUG_INFO_MAP ? map.get(executable) : null);
77+
}
78+
79+
/**
80+
* Inspects the target class.
81+
* <p>Exceptions will be logged, and a marker map returned to indicate the
82+
* lack of debug information.
83+
*/
84+
private Map<Executable, String[]> inspectClass(Class<?> clazz) {
85+
InputStream is = clazz.getResourceAsStream(ClassUtils.getClassFileName(clazz));
86+
if (is == null) {
87+
// We couldn't load the class file, which is not fatal as it
88+
// simply means this method of discovering parameter names won't work.
89+
if (logger.isDebugEnabled()) {
90+
logger.debug("Cannot find '.class' file for class [" + clazz
91+
+ "] - unable to determine constructor/method parameter names");
92+
}
93+
return NO_DEBUG_INFO_MAP;
94+
}
95+
// We cannot use try-with-resources here for the InputStream, since we have
96+
// custom handling of the close() method in a finally-block.
97+
try {
98+
ClassReader classReader = new ClassReader(is);
99+
Map<Executable, String[]> map = new ConcurrentHashMap<>(32);
100+
classReader.accept(new ParameterNameDiscoveringVisitor(clazz, map), 0);
101+
if (logger.isWarnEnabled()) {
102+
logger
103+
.warn("Using deprecated '-debug' fallback for parameter name resolution. Compile the "
104+
+ "affected code with '-parameters' instead or avoid its introspection: "
105+
+ clazz.getName());
106+
}
107+
return map;
108+
} catch (IOException ex) {
109+
if (logger.isDebugEnabled()) {
110+
logger.debug("Exception thrown while reading '.class' file for class [" + clazz
111+
+ "] - unable to determine constructor/method parameter names", ex);
112+
}
113+
} catch (IllegalArgumentException ex) {
114+
if (logger.isDebugEnabled()) {
115+
logger
116+
.debug(
117+
"ASM ClassReader failed to parse class file ["
118+
+ clazz
119+
+ "], probably due to a new Java class file version that isn't supported yet "
120+
+ "- unable to determine constructor/method parameter names", ex);
121+
}
122+
} finally {
123+
try {
124+
is.close();
125+
} catch (IOException ex) {
126+
// ignore
127+
}
128+
}
129+
return NO_DEBUG_INFO_MAP;
130+
}
131+
132+
/**
133+
* Helper class that inspects all methods and constructors and then
134+
* attempts to find the parameter names for the given {@link Executable}.
135+
*/
136+
private static class ParameterNameDiscoveringVisitor extends ClassVisitor {
137+
138+
private static final String STATIC_CLASS_INIT = "<clinit>";
139+
140+
private final Class<?> clazz;
141+
142+
private final Map<Executable, String[]> executableMap;
143+
144+
public ParameterNameDiscoveringVisitor(Class<?> clazz,
145+
Map<Executable, String[]> executableMap) {
146+
super(SpringAsmInfo.ASM_VERSION);
147+
this.clazz = clazz;
148+
this.executableMap = executableMap;
149+
}
150+
151+
@Override
152+
@Nullable
153+
public MethodVisitor visitMethod(int access, String name, String desc, String signature,
154+
String[] exceptions) {
155+
// exclude synthetic + bridged && static class initialization
156+
if (!isSyntheticOrBridged(access) && !STATIC_CLASS_INIT.equals(name)) {
157+
return new LocalVariableTableVisitor(this.clazz, this.executableMap, name, desc,
158+
isStatic(access));
159+
}
160+
return null;
161+
}
162+
163+
private static boolean isSyntheticOrBridged(int access) {
164+
return (((access & Opcodes.ACC_SYNTHETIC) | (access & Opcodes.ACC_BRIDGE)) > 0);
165+
}
166+
167+
private static boolean isStatic(int access) {
168+
return ((access & Opcodes.ACC_STATIC) > 0);
169+
}
170+
}
171+
172+
private static class LocalVariableTableVisitor extends MethodVisitor {
173+
174+
private static final String CONSTRUCTOR = "<init>";
175+
176+
private final Class<?> clazz;
177+
178+
private final Map<Executable, String[]> executableMap;
179+
180+
private final String name;
181+
182+
private final Type[] args;
183+
184+
private final String[] parameterNames;
185+
186+
private final boolean isStatic;
187+
188+
private boolean hasLvtInfo = false;
189+
190+
/*
191+
* The nth entry contains the slot index of the LVT table entry holding the
192+
* argument name for the nth parameter.
193+
*/
194+
private final int[] lvtSlotIndex;
195+
196+
public LocalVariableTableVisitor(Class<?> clazz, Map<Executable, String[]> map,
197+
String name, String desc, boolean isStatic) {
198+
super(SpringAsmInfo.ASM_VERSION);
199+
this.clazz = clazz;
200+
this.executableMap = map;
201+
this.name = name;
202+
this.args = Type.getArgumentTypes(desc);
203+
this.parameterNames = new String[this.args.length];
204+
this.isStatic = isStatic;
205+
this.lvtSlotIndex = computeLvtSlotIndices(isStatic, this.args);
206+
}
207+
208+
@Override
209+
public void visitLocalVariable(String name, String description, String signature,
210+
Label start, Label end, int index) {
211+
this.hasLvtInfo = true;
212+
for (int i = 0; i < this.lvtSlotIndex.length; i++) {
213+
if (this.lvtSlotIndex[i] == index) {
214+
this.parameterNames[i] = name;
215+
}
216+
}
217+
}
218+
219+
@Override
220+
public void visitEnd() {
221+
if (this.hasLvtInfo || (this.isStatic && this.parameterNames.length == 0)) {
222+
// visitLocalVariable will never be called for static no args methods
223+
// which doesn't use any local variables.
224+
// This means that hasLvtInfo could be false for that kind of methods
225+
// even if the class has local variable info.
226+
this.executableMap.put(resolveExecutable(), this.parameterNames);
227+
}
228+
}
229+
230+
private Executable resolveExecutable() {
231+
ClassLoader loader = this.clazz.getClassLoader();
232+
Class<?>[] argTypes = new Class<?>[this.args.length];
233+
for (int i = 0; i < this.args.length; i++) {
234+
argTypes[i] = ClassUtils.resolveClassName(this.args[i].getClassName(), loader);
235+
}
236+
try {
237+
if (CONSTRUCTOR.equals(this.name)) {
238+
return this.clazz.getDeclaredConstructor(argTypes);
239+
}
240+
return this.clazz.getDeclaredMethod(this.name, argTypes);
241+
} catch (NoSuchMethodException ex) {
242+
throw new IllegalStateException(
243+
"Method ["
244+
+ this.name
245+
+ "] was discovered in the .class file but cannot be resolved in the class object",
246+
ex);
247+
}
248+
}
249+
250+
private static int[] computeLvtSlotIndices(boolean isStatic, Type[] paramTypes) {
251+
int[] lvtIndex = new int[paramTypes.length];
252+
int nextIndex = (isStatic ? 0 : 1);
253+
for (int i = 0; i < paramTypes.length; i++) {
254+
lvtIndex[i] = nextIndex;
255+
if (isWideType(paramTypes[i])) {
256+
nextIndex += 2;
257+
} else {
258+
nextIndex++;
259+
}
260+
}
261+
return lvtIndex;
262+
}
263+
264+
private static boolean isWideType(Type aType) {
265+
// float is not a wide type
266+
return (aType == Type.LONG_TYPE || aType == Type.DOUBLE_TYPE);
267+
}
268+
}
269+
270+
}

sofa-boot-project/sofaboot-dependencies/pom.xml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<maven-java-formatter-plugin.version>0.4</maven-java-formatter-plugin.version>
2020
<maven-pmd-plgun.version>3.19.0</maven-pmd-plgun.version>
2121
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
22-
<maven-jacoco-plugin.version>0.8.9</maven-jacoco-plugin.version>
22+
<maven-jacoco-plugin.version>0.8.11</maven-jacoco-plugin.version>
2323
<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>
2424
<!-- sofa stack lib-->
2525
<sofa.registry.version>6.1.8</sofa.registry.version>
@@ -28,11 +28,11 @@
2828
<sofa.common.tools.version>2.0.1</sofa.common.tools.version>
2929
<sofa.bolt.version>1.6.6</sofa.bolt.version>
3030
<sofa.hessian.version>3.5.1</sofa.hessian.version>
31-
<sofa.ark.version>2.2.3</sofa.ark.version>
31+
<sofa.ark.version>3.0.1-SNAPSHOT</sofa.ark.version>
3232
<sofa.lookout.version>1.6.1</sofa.lookout.version>
3333
<!--3rd lib dependency-->
34-
<spring.cloud.version>2022.0.3</spring.cloud.version>
35-
<asm.version>9.4</asm.version>
34+
<spring.cloud.version>2023.0.0</spring.cloud.version>
35+
<asm.version>9.5</asm.version>
3636
<fastjson.version>1.2.83</fastjson.version>
3737
<javassist.version>3.29.2-GA</javassist.version>
3838
<protobuf.version>3.22.2</protobuf.version>
@@ -537,18 +537,6 @@
537537
<version>${commons.io.version}</version>
538538
</dependency>
539539

540-
<dependency>
541-
<groupId>mysql</groupId>
542-
<artifactId>mysql-connector-java</artifactId>
543-
<version>${mysql.version}</version>
544-
<exclusions>
545-
<exclusion>
546-
<groupId>com.google.protobuf</groupId>
547-
<artifactId>protobuf-java</artifactId>
548-
</exclusion>
549-
</exclusions>
550-
</dependency>
551-
552540
<dependency>
553541
<groupId>com.alibaba</groupId>
554542
<artifactId>druid</artifactId>

sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-rpc/src/main/java/com/alipay/sofa/smoke/tests/rpc/boot/RpcSofaBootApplication.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818

1919
import org.springframework.boot.SpringApplication;
2020
import org.springframework.boot.autoconfigure.SpringBootApplication;
21-
import org.springframework.context.annotation.ComponentScan;
22-
import org.springframework.context.annotation.FilterType;
2321

2422
/**
2523
*
2624
* @author yuanxuan
2725
* @version : RpcSofaBootApplication.java, v 0.1 2023年02月03日 15:19 yuanxuan Exp $
2826
*/
29-
@SpringBootApplication
30-
@ComponentScan(excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.alipay.sofa.smoke.tests.rpc.boot.*") })
27+
@SpringBootApplication(scanBasePackages = "none")
3128
public class RpcSofaBootApplication {
3229

3330
public static void main(String[] args) {

sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-tracer/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
</dependency>
4343

4444
<dependency>
45-
<groupId>mysql</groupId>
46-
<artifactId>mysql-connector-java</artifactId>
45+
<groupId>com.mysql</groupId>
46+
<artifactId>mysql-connector-j</artifactId>
4747
</dependency>
4848

4949
<dependency>

0 commit comments

Comments
 (0)