diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala index 2430bf40492..6df3d696049 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala @@ -28,10 +28,12 @@ class FragmentParameterTypingParser(classLoader: ClassLoader, classDefinitions: val setPattern = "Set\\[(.+)\\]".r Try(className match { - case mapPattern(x, y) => + case mapPattern(x, y) if x == "String" => val resolvedFirstTypeParam = resolveInnerClass(x) val resolvedSecondTypeParam = resolveInnerClass(y) Typed.genericTypeClass[java.util.Map[_, _]](List(resolvedFirstTypeParam, resolvedSecondTypeParam)) + case mapPattern(_, _) => + throw new IllegalArgumentException("Obtained map with non string key") case listPattern(x) => val resolvedTypeParam = resolveInnerClass(x) Typed.genericTypeClass[java.util.List[_]](List(resolvedTypeParam)) diff --git a/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/NodeDataValidatorSpec.scala b/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/NodeDataValidatorSpec.scala index fd2c8d9b334..f5ad47b71ff 100644 --- a/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/NodeDataValidatorSpec.scala +++ b/scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/NodeDataValidatorSpec.scala @@ -1160,6 +1160,35 @@ class NodeDataValidatorSpec extends AnyFunSuite with Matchers with Inside with T } } + test("should not allow creation of inline map with non string keys in FragmentInputDefinition") { + val nodeId: String = "in" + val paramName = "param1" + + inside( + validate( + FragmentInputDefinition( + nodeId, + List( + FragmentParameter( + ParameterName(paramName), + FragmentClazzRef("Map[Long, Double]"), + required = false, + initialValue = None, + hintText = None, + valueEditor = None, + valueCompileTimeValidation = None + ) + ), + ), + ValidationContext.empty, + Map.empty, + outgoingEdges = List(OutgoingEdge("any", Some(FragmentOutput("out1")))) + ) + ) { case ValidationPerformed(errors, None, None) => + errors shouldBe List(FragmentParamClassLoadError(ParameterName("param1"), "Map[Long, Double]", "in")) + } + } + test( "should not allow usage of generic type in FragmentInputDefinition parameter when occurring type is not on classpath" ) {