Skip to content

Commit

Permalink
Fix for spel validations: Typing type reference with class starting f…
Browse files Browse the repository at this point in the history
…rom lower case caused nasty error
  • Loading branch information
arkadius committed Jun 12, 2023
1 parent d939674 commit b2be258
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* [#4346](https://github.com/TouK/nussknacker/pull/4346) Improvement: Don't fetch process state for fragment
* [#4342](https://github.com/TouK/nussknacker/pull/4342) Improvement: Don't run custom action on archived scenario and fragment
* [#4302](https://github.com/TouK/nussknacker/pull/4302) State inconsistency detection was moved from designer to DeploymentManager.
* [#4360](https://github.com/TouK/nussknacker/pull/4360) Fix for spel validations: Typing type reference with class starting from lower case e.g. T(foo) caused nasty error

1.9.1 (24 Apr 2023)
------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ class TypeReferenceTyper(evaluationContext: EvaluationContext,
case None => Writer(List(TypeReferenceError(typeReferenceClazz.toString)), Unknown)
}
case Success(other) => throw new IllegalStateException(s"Not expected returned type: $other for TypeReference. Should be Class[_]")
case Failure(_: EvaluationException) => Writer(List(UnknownClassError(typeReference.toStringAST)), Unknown)
// SpEL's TypeReference handles in a specific way situation when type starts with lower case and has no dot - it looks for
// things like T(object), T(double) etc. If it can't find it, it throws IllegalArgumentException
case Failure(_: IllegalArgumentException) => Writer(List(UnknownClassError(extractClassName(typeReference))), Unknown)
case Failure(_: EvaluationException) => Writer(List(UnknownClassError(extractClassName(typeReference))), Unknown)
case Failure(exception) => throw exception
}

}

// extracts xyz from T(xyz)
private def extractClassName(typeReference: TypeReference) = {
val withoutPrefix = typeReference.toStringAST.drop(2)
withoutPrefix.take(withoutPrefix.length - 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ class SpelExpressionSpec extends AnyFunSuite with Matchers with ValidatedValuesD
test("evaluate static method call on non-existing class") {
inside(parse[Any]("T(java.lang.NonExistingClass).method()")) {
case Invalid(NonEmptyList(error: UnknownClassError, _)) =>
error.message shouldBe "Class T(java.lang.NonExistingClass) does not exist"
error.message shouldBe "Class java.lang.NonExistingClass does not exist"
}
}

test("not throw an exception when is used lower case type") {
parse[Any]("T(foo).bar", ctx) should matchPattern {
case Invalid(NonEmptyList(UnknownClassError("foo"), _)) =>
}
}

Expand Down

0 comments on commit b2be258

Please sign in to comment.