Skip to content

Commit

Permalink
add init error throw
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Dec 3, 2023
1 parent e8abb63 commit a90dc43
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/com/alibaba/fastjson2/util/JDKUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.alibaba.fastjson2.util;

import com.alibaba.fastjson2.JSONException;
import sun.misc.Unsafe;

import java.lang.invoke.*;
Expand Down Expand Up @@ -76,13 +77,18 @@ public class JDKUtils {
unsafe = (Unsafe) theUnsafeField.get(null);
offset = unsafe.arrayBaseOffset(byte[].class);
charOffset = unsafe.arrayBaseOffset(char[].class);
} catch (Throwable ignored) {
// ignored
} catch (Throwable e) {
initErrorLast = e;
}

UNSAFE = unsafe;
ARRAY_BYTE_BASE_OFFSET = offset;
ARRAY_CHAR_BASE_OFFSET = charOffset;

if (offset == -1) {
throw new JSONException("init JDKUtils error", initErrorLast);
}

int jvmVersion = -1, android_sdk_int = -1;
boolean openj9 = false, android = false, graal = false;
try {
Expand Down

0 comments on commit a90dc43

Please sign in to comment.