Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private TypeSet() {}
* Build a type with the provided name. If the provided name is null or
* the empty string, the empty type will be returned.
*/
public static Type type(String value) {
public static synchronized Type type(String value) {
return implementation.makeOrGetType(value);
}

Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/com/github/gumtreediff/test/TestTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import com.github.gumtreediff.tree.*;
import org.junit.jupiter.api.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static org.junit.jupiter.api.Assertions.*;

public class TestTree {
Expand Down Expand Up @@ -285,4 +288,25 @@ public void testToString() {
t3.setLength(2);
assertEquals("foo: hello [1,3]", t3.toString());
}

@Test
public void testTypeThreading() throws InterruptedException {
int n = 20;
ExecutorService exec = Executors.newFixedThreadPool(n);
List<Type> types = new ArrayList<>();

for (int i = 0; i < n; i++) {
exec.submit(() -> {
types.add(TypeSet.type("foo"));
});
}

exec.awaitTermination(1, java.util.concurrent.TimeUnit.SECONDS);

for (Type t1 : types) {
for (Type t2: types) {
assertSame(t1, t2);
}
}
}
}