Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ETuple: Avoid race conditions wrt. defining a tuple class.

Symptom was:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at erjang.ERT.defineClass(ERT.java)
	...
Caused by: java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): attempted  duplicate class definition for name: "erjang/ETuple40"
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
	...
  • Loading branch information...
commit 299636d5fec7ef850167a06c9fd9d454cd468879 1 parent 5737ecb
@eriksoe eriksoe authored
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/main/java/erjang/ETuple.java
View
12 src/main/java/erjang/ETuple.java
@@ -199,11 +199,19 @@ private static ETuple make_big(int size) {
byte[] data = make_tuple_class_data(num_cells);
- dump(ETUPLE_NAME + num_cells, data);
+ //dump(ETUPLE_NAME + num_cells, data);
String name = (ETUPLE_NAME + num_cells).replace('/', '.');
- return ERT.defineClass(ETuple.class.getClassLoader(), name, data);
+ synchronized (ETuple.class) { // Avoid race conditions
+ try {
+ // Has the class been defined in the meantime?
+ return (Class<? extends ETuple>) Class.forName(ETuple.class.getName() + num_cells);
+ } catch (ClassNotFoundException e) {
+ // It is still not defined - do it
+ return ERT.defineClass(ETuple.class.getClassLoader(), name, data);
+ }
+ }
}
static byte[] make_tuple_class_data(int num_cells) {

0 comments on commit 299636d

Please sign in to comment.
Something went wrong with that request. Please try again.