Fixes infinite loop in dependency checker in some cases

This commit is contained in:
konsoletyper 2014-02-21 19:47:51 +04:00
parent a353a05e23
commit 7831ade3a6
3 changed files with 21 additions and 1 deletions

View File

@ -56,6 +56,13 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
buffer = new char[capacity]; buffer = new char[capacity];
} }
public TAbstractStringBuilder(TString value) {
buffer = new char[value.length()];
for (int i = 0; i < buffer.length; ++i) {
buffer[i] = value.charAt(i);
}
}
protected TAbstractStringBuilder append(TString string) { protected TAbstractStringBuilder append(TString string) {
if (string == null) { if (string == null) {
string = TString.wrap("null"); string = TString.wrap("null");

View File

@ -28,6 +28,10 @@ public class TStringBuilder extends TAbstractStringBuilder implements TAppendabl
super(); super();
} }
public TStringBuilder(TString value) {
super(value);
}
@Override @Override
public TStringBuilder append(TString string) { public TStringBuilder append(TString string) {
super.append(string); super.append(string);

View File

@ -33,12 +33,21 @@ public class DependencyNode implements ValueDependencyInfo {
private volatile String tag; private volatile String tag;
private final AtomicReference<DependencyNode> arrayItemNode = new AtomicReference<>(); private final AtomicReference<DependencyNode> arrayItemNode = new AtomicReference<>();
private volatile CountDownLatch arrayItemNodeLatch = new CountDownLatch(1); private volatile CountDownLatch arrayItemNodeLatch = new CountDownLatch(1);
private int degree;
DependencyNode(DependencyChecker dependencyChecker) { DependencyNode(DependencyChecker dependencyChecker) {
this(dependencyChecker, 0);
}
DependencyNode(DependencyChecker dependencyChecker, int degree) {
this.dependencyChecker = dependencyChecker; this.dependencyChecker = dependencyChecker;
this.degree = degree;
} }
public void propagate(String type) { public void propagate(String type) {
if (degree > 2) {
return;
}
if (types.putIfAbsent(type, mapValue) == null) { if (types.putIfAbsent(type, mapValue) == null) {
if (DependencyChecker.shouldLog) { if (DependencyChecker.shouldLog) {
System.out.println(tag + " -> " + type); System.out.println(tag + " -> " + type);
@ -75,7 +84,7 @@ public class DependencyNode implements ValueDependencyInfo {
public DependencyNode getArrayItem() { public DependencyNode getArrayItem() {
DependencyNode result = arrayItemNode.get(); DependencyNode result = arrayItemNode.get();
if (result == null) { if (result == null) {
result = new DependencyNode(dependencyChecker); result = new DependencyNode(dependencyChecker, degree + 1);
if (arrayItemNode.compareAndSet(null, result)) { if (arrayItemNode.compareAndSet(null, result)) {
if (DependencyChecker.shouldLog) { if (DependencyChecker.shouldLog) {
arrayItemNode.get().tag = tag + "["; arrayItemNode.get().tag = tag + "[";