jenkinsci / groovy-sandbox

(Deprecated) Compile-time transformer to run Groovy code in a restrictive sandbox
MIT License
123 stars 60 forks source link

Fix interception of return statements in closures #100

Closed dwnusbaum closed 1 year ago

dwnusbaum commented 1 year ago

Fixes #99

The code related to intercepting implicit Groovy casts in method return values in https://github.com/jenkinsci/groovy-sandbox/commit/520243213bcd8c81322e8e683daa8d555bb4f484 caused two related bugs for closure expressions with explicit return statements:

  1. Closures that are not inside of a method (e.g. they are defined using @Field) and have explicit return statements cause an NPE during compilation
  2. For Closures that are inside of a method and have explicit return statements, the sandbox transforms the return statement and inserts a checked cast to the return type of the surrounding method, which is incorrect