From 48e0bda8e45286b2bcc65b75e0364e2223ba3ec4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 27 Feb 2019 14:10:32 +0200 Subject: [PATCH] Check that both returnTypeDesc and parameterTypeDescs are initialized Change-Id: I6b3004ab9119ceef7ae0431cea64b28c8819fc4a --- .../scl/compiler/constants/JavaStaticMethod.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/JavaStaticMethod.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/JavaStaticMethod.java index 9e071e9cb..a72b844ba 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/JavaStaticMethod.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/JavaStaticMethod.java @@ -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( -- 2.43.2