]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Check that both returnTypeDesc and parameterTypeDescs are initialized 33/2733/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 27 Feb 2019 12:10:32 +0000 (14:10 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 27 Feb 2019 12:10:32 +0000 (14:10 +0200)
Change-Id: I6b3004ab9119ceef7ae0431cea64b28c8819fc4a

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/JavaStaticMethod.java

index 9e071e9cb9002c700d9c398fec92a3b4eafca8ff..a72b844bae99c89cea35cc1304678da62209df4f 100644 (file)
@@ -56,6 +56,8 @@ public class JavaStaticMethod extends FunctionValue {
                     if(td.equals(TypeDesc.VOID))
                         throw new InternalCompilerError();
         }
+        if( (returnTypeDesc == null) != (parameterTypeDescs == null) )
+            throw new IllegalArgumentException("Either specify both returnTypeDesc and parameterTypeDescs or neither");
         ClassBuilder.checkClassName(className);
         this.className = className;
         this.methodName = methodName;
@@ -73,8 +75,11 @@ public class JavaStaticMethod extends FunctionValue {
     }
     
     @Override
-    public Type applyExact(MethodBuilder mb, Val[] parameters) {        
-        if(returnTypeDesc == null) {
+    public Type applyExact(MethodBuilder mb, Val[] parameters) {
+        if(returnTypeDesc == null || parameterTypeDescs == null) {
+            // This method may be called from multiple threads at the same time when returnTypeDesc
+            // and parameterTypeDescs are uninitialized. Double initialization is OK in this case,
+            // but because there are two fields, we have to check that both are initialized.             
             JavaTypeTranslator tt = mb.getJavaTypeTranslator();
             returnTypeDesc = tt.toTypeDesc(returnType);
             parameterTypeDescs = JavaTypeTranslator.filterVoid(