Set#remove(Object) 肯定是在 Java 1.3 中定义的。该错误实际上是说 ThreadLocal#remove()V 不存在。那是在 1.5 中出现的。(看到了吗?没有这种方法!)
这是 json-lib 2.4 (jdk1.3) 中的错误来源
抽象JSON:
/**
* Removes a reference for cycle detection check.
*/
protected static void removeInstance( Object instance ) {
Set set = getCycleSet();
set.remove( instance );
if(set.size() == 0) {
cycleSet.remove(); // BUG @ "line 221"
}
}
因为在 CycleSet.java 我们看到:
private static class CycleSet extends ThreadLocal {
protected Object initialValue() {
return new SoftReference(new HashSet());
}
public Set getSet() {
Set set = (Set) ((SoftReference)get()).get();
if( set == null ) {
set = new HashSet();
set(new SoftReference(set));
}
return set;
}
}
但是 ThreadLocal (1.3) 没有这样的方法。
[在@AlexR 回答/评论后编辑]:
鉴于该库是开源的,我认为这可能会解决它(未经测试):
private static class CycleSet extends ThreadLocal {
protected Object initialValue() {
return new SoftReference(new HashSet());
}
/** added to support JRE 1.3 */
public void remove() {
this.set(null);
}
public Set getSet() {
Set set = (Set) ((SoftReference)get()).get();
if( set == null ) {
set = new HashSet();
set(new SoftReference(set));
}
return set;
}
}