1
0
mirror of synced 2025-12-17 04:43:15 +08:00

🎨 #3732 Add Quarkus/GraalVM Native Image support - Fix Random instance initialization issues

This commit is contained in:
Copilot
2025-11-02 16:30:13 +08:00
committed by GitHub
parent e9bc5d0109
commit bb573afcaf
7 changed files with 182 additions and 13 deletions

View File

@@ -4,12 +4,24 @@ public class RandomUtils {
private static final String RANDOM_STR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
private static final java.util.Random RANDOM = new java.util.Random();
private static volatile java.util.Random random;
private static java.util.Random getRandom() {
if (random == null) {
synchronized (RandomUtils.class) {
if (random == null) {
random = new java.util.Random();
}
}
}
return random;
}
public static String getRandomStr() {
StringBuilder sb = new StringBuilder();
java.util.Random r = getRandom();
for (int i = 0; i < 16; i++) {
sb.append(RANDOM_STR.charAt(RANDOM.nextInt(RANDOM_STR.length())));
sb.append(RANDOM_STR.charAt(r.nextInt(RANDOM_STR.length())));
}
return sb.toString();
}

View File

@@ -37,6 +37,19 @@ public class WxCryptUtil {
private static final Base64 BASE64 = new Base64();
private static final Charset CHARSET = StandardCharsets.UTF_8;
private static volatile Random random;
private static Random getRandom() {
if (random == null) {
synchronized (WxCryptUtil.class) {
if (random == null) {
random = new Random();
}
}
}
return random;
}
private static final ThreadLocal<DocumentBuilder> BUILDER_LOCAL = ThreadLocal.withInitial(() -> {
try {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -109,10 +122,10 @@ public class WxCryptUtil {
*/
private static String genRandomStr() {
String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
Random r = getRandom();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 16; i++) {
int number = random.nextInt(base.length());
int number = r.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();

View File

@@ -0,0 +1,4 @@
Args = --initialize-at-run-time=org.apache.http.impl.auth.NTLMEngineImpl \
--initialize-at-run-time=org.apache.http.impl.auth.NTLMEngine \
--initialize-at-run-time=org.apache.http.impl.auth.KerberosScheme \
--initialize-at-run-time=org.apache.http.impl.auth.SPNegoScheme

View File

@@ -0,0 +1,14 @@
[
{
"name": "me.chanjar.weixin.common.util.RandomUtils",
"methods": [
{"name": "getRandomStr", "parameterTypes": []}
]
},
{
"name": "me.chanjar.weixin.common.util.crypto.WxCryptUtil",
"allDeclaredConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
}
]