FST fast-serialization 1.52版本中一个造成代码死循环的BUG

public class FSTClazzInfoRegistry {    
 ... ...
  public FSTClazzInfo getCLInfo(Class c) {
        //1).此处会出现死循环,而且线程一直是运行状态
        while(!rwLock.compareAndSet(false,true));
        FSTClazzInfo res = (FSTClazzInfo) mInfos.get(c);
        if ( res == null ) {
            if ( c == null ) {
                rwLock.set(false);
                throw new NullPointerException("Class is null");
            }
            //2).在构造FSTClazzInfo对象时会抛出运行时异常,一旦抛出异常造成代码1处死循环
            res = new FSTClazzInfo(c, this, ignoreAnnotations);
            mInfos.put( c, res );
        }
        rwLock.set(false);
        return res;
    }
 ... ...
}


public final class FSTClazzInfo {
	... ...
    public FSTClazzInfo(Class clazz, FSTClazzInfoRegistry infoRegistry, boolean ignoreAnnotations) {
        this.clazz = clazz;
        enumConstants = clazz.getEnumConstants();
        reg = infoRegistry;
        ignoreAnn = ignoreAnnotations;
        createFields(clazz);
        if ( !reg.isStructMode() ) {
            if (Externalizable.class.isAssignableFrom(clazz)) {
                externalizable = true;
                cons = FSTUtil.findConstructorForExternalize(clazz);
            } else if (Serializable.class.isAssignableFrom(clazz) || clazz == Object.class ) {
                externalizable = false;
                cons = FSTUtil.findConstructorForSerializable(clazz);
            } else {
                //3).一旦需要序列化的对象没有实现Serializable接口或Externalizable接口的话,就会抛出运行时异常
                throw new RuntimeException("Class "+clazz.getName()+" does not implement Serializable or externalizable");
            }
            if ( ! ignoreAnnotations ) {
                Predict annotation = (Predict) clazz.getAnnotation(Predict.class);
                if (annotation != null) {
                    predict = annotation.value();
                } else { 
                      //default predictions (disabled, no speedup)
//                    if ( clazz == List.class ) {
//                        predict = new Class[]{ArrayList.class};
//                    } else if ( clazz == Map.class ) {
//                        predict = new Class[]{HashMap.class};
//                    }
                }
                equalIsIdentity = clazz.isAnnotationPresent(EqualnessIsIdentity.class);
                equalIsBinary = clazz.isAnnotationPresent(EqualnessIsBinary.class);
                flat = clazz.isAnnotationPresent(Flat.class);
            }
        }

        if (cons != null) {
            cons.setAccessible(true);
        }

        final String name = clazz.getName();
        if (name.length()<127) {
            isAsciiNameShortString = true;
            for (int i=0; i < name.length();i++) {
                if (name.charAt(i) > 127) {
                    isAsciiNameShortString = false;
                    break;
                }
            }
        }

        requiresInit = isExternalizable() || useCompatibleMode() || hasTransient;
    }
   ... ...
}



你可能感兴趣的:(FST fast-serialization 1.52版本中一个造成代码死循环的BUG)