alibaba / alibaba/fastjson2

[BUG] Default proguard rules may contain error

Open
#3,775 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

This is the error that I'd encountered:
```
Exception in thread "main" java.lang.ExceptionInInitializerError
at a.a(Unknown Source)
at uC.(Unknown Source)
at uz.a(Unknown Source)
at main(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: chars
at java.base/java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.(AtomicReferenceFieldUpdater.java:334)
at java.base/java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:112)
at f.(Unknown Source)
... 4 more
Caused by: java.lang.NoSuchFieldException: chars
at java.base/java.lang.Class.getDeclaredField(Class.java:2384)
at java.base/java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.(AtomicReferenceFieldUpdater.java:328)
... 6 more
```
And these are the rules that I'd added
```
-keepclassmembers class com.alibaba.fastjson2.JSONFactory$CacheItem {;}
-keepclassmembers class com.alibaba.fastjson2.util.TypeUtils$Cache {;}
```
I think that the document should be updated. These are the optimized proguard rules
```
-keepclassmembers class com.alibaba.fastjson2.JSONFactory$CacheItem {;}
-keepclassmembers class com.alibaba.fastjson2.util.TypeUtils$Cache {;}
-keep, allowoptimization, allowobfuscation @com.alibaba.fastjson2.annotation.JSONType class *
# Keep the fields and methods with @JSONField
-keepclassmembers, allowobfuscation class * {
@com.alibaba.fastjson2.annotation.JSONField ;
@com.alibaba.fastjson2.annotation.JSONField ;
}

# Keep any (anonymous) classes extending TypeReference
-keep, allowobfuscation class com.alibaba.fastjson2.TypeReference
-keep, allowobfuscation class * extends com.alibaba.fastjson2.TypeReference
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported ExceptionInInitializerError with the default and optimized ProGuard rules shown in the issue. Compare those rules with the documentation and determine whether the default configuration causes the missing chars field; done means the rules or documentation accurately prevent or explain the failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.