Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ContextAutoTypeBeforeHandler 跨 ClassLoader 使用时 classCache 缓存会导致类转换异常 #753

Closed
AlbumenJ opened this issue Sep 11, 2022 · 1 comment
Labels
bug Something isn't working fixed
Milestone

Comments

@AlbumenJ
Copy link

问题描述

ContextAutoTypeBeforeHandler 跨 ClassLoader 使用时 classCache 缓存会导致类转换异常

重现步骤

部分代码省略

public class ContextAutoTypeBeforeHandler
        implements JSONReader.AutoTypeBeforeHandler {
    final Map<String, Class> classCache = new ConcurrentHashMap<>(16, 0.75f, 1);

    @Override
    public Class<?> apply(String typeName, Class<?> expectClass, long features) {
        
            if (Arrays.binarySearch(acceptHashCodes, hash) >= 0) {
                Class clazz = classCache.get(typeName);

                if (clazz == null) {
                    clazz = loadClass(typeName);
                    if (clazz != null) {
                        Class origin = classCache.putIfAbsent(typeName, clazz);
                        if (origin != null) {
                            clazz = origin;
                        }
                    }
                }

                if (clazz != null) {
                    return clazz;
                }
            }
        }
    }
}
@AlbumenJ AlbumenJ added the bug Something isn't working label Sep 11, 2022
@wenshao wenshao added this to the 2.0.14 milestone Sep 11, 2022
@wenshao wenshao added the fixed label Sep 11, 2022
@wenshao
Copy link
Member

wenshao commented Sep 16, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.14
问题已修复,请用新版本

@wenshao wenshao closed this as completed Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants