Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-37479

Unclassified staticMethod java.nio.file.Paths get java.lang.String

    Details

    • Similar Issues:

      Description

      When attempting to run the expression new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get("/some/path"))) in a sandboxed pipeline script, I get the following error:

      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified staticMethod java.nio.file.Paths get java.lang.String

      Also, no approval appears at /scriptApproval.

        Attachments

          Activity

          Hide
          gohla Gabriel Konat added a comment -

          Same problem here on Jenkins 2.23. Static method is rejected, but does not show up in the 'In-process Script Approval' page. I even manually added 'staticMethod java.lang.Math round java.math.BigDecimal' as an approved signature to the script approval XML file and restarted Jenkins, but the method is still rejected.

          Exception:

          org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified staticMethod java.lang.Math round java.math.BigDecimal
          	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onStaticCall(SandboxInterceptor.java:138)
          	at org.kohsuke.groovy.sandbox.impl.Checker$2.call(Checker.java:180)
          	at org.kohsuke.groovy.sandbox.impl.Checker.checkedStaticCall(Checker.java:177)
          	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:91)
          	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:16)
          	at WorkflowScript.createMessage(WorkflowScript:177)
          	at WorkflowScript.notifyFail(WorkflowScript:190)
          	at WorkflowScript.run(WorkflowScript:140)
          	at ___cps.transform___(Native Method)
          	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:48)
          	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
          	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
          	at sun.reflect.GeneratedMethodAccessor279.invoke(Unknown Source)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          	at java.lang.reflect.Method.invoke(Method.java:497)
          	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
          	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:50)
          	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
          	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
          	at sun.reflect.GeneratedMethodAccessor279.invoke(Unknown Source)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          	at java.lang.reflect.Method.invoke(Method.java:497)
          	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
          	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
          	at com.cloudbees.groovy.cps.Next.step(Next.java:58)
          	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
          	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
          	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
          	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
          	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
          	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
          	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163)
          	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:324)
          	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:78)
          	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:236)
          	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:224)
          	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63)
          	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
          	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
          	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          	at java.lang.Thread.run(Thread.java:745)
          
          Show
          gohla Gabriel Konat added a comment - Same problem here on Jenkins 2.23. Static method is rejected, but does not show up in the 'In-process Script Approval' page. I even manually added 'staticMethod java.lang.Math round java.math.BigDecimal' as an approved signature to the script approval XML file and restarted Jenkins, but the method is still rejected. Exception: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified staticMethod java.lang. Math round java.math.BigDecimal at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onStaticCall(SandboxInterceptor.java:138) at org.kohsuke.groovy.sandbox.impl.Checker$2.call(Checker.java:180) at org.kohsuke.groovy.sandbox.impl.Checker.checkedStaticCall(Checker.java:177) at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:91) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:16) at WorkflowScript.createMessage(WorkflowScript:177) at WorkflowScript.notifyFail(WorkflowScript:190) at WorkflowScript.run(WorkflowScript:140) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:48) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82) at sun.reflect.GeneratedMethodAccessor279.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:50) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82) at sun.reflect.GeneratedMethodAccessor279.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72) at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21) at com.cloudbees.groovy.cps.Next.step(Next.java:58) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:324) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:78) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:236) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:224) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang. Thread .run( Thread .java:745)
          Hide
          jglick Jesse Glick added a comment -

          “Unclassified method” errors generally indicate a bug in the script-security plugin; there is nothing to approve because it means Jenkins was unable to determine what the script was attempting to call. For diagnosis please supply a complete, minimal script reproducing the error.

          Show
          jglick Jesse Glick added a comment - “Unclassified method” errors generally indicate a bug in the script-security plugin; there is nothing to approve because it means Jenkins was unable to determine what the script was attempting to call. For diagnosis please supply a complete, minimal script reproducing the error.
          Hide
          gohla Gabriel Konat added a comment -

          I see. The following pipeline script triggers the exception:

          echo Math.round(currentBuild.duration / 1000)
          
          Show
          gohla Gabriel Konat added a comment - I see. The following pipeline script triggers the exception: echo Math .round(currentBuild.duration / 1000)
          Hide
          jgsqware Julien Garcia Gonzalez added a comment -

          Hello,

          I got the same on

          echo Math.ceil(10.234)

          Show
          jgsqware Julien Garcia Gonzalez added a comment - Hello, I got the same on echo Math.ceil(10.234)
          Hide
          grayaii Alex Gray added a comment -

          Not sure if this helps people, but as a workaround, you can run your script like so:

          java -jar jenkins-cli.jar -remoting -noCertificateCheck -i id_rsa -s JENKINS_URL groovy /tmp/my_script.groovy

          where /tmp/my_script.groovy contains:

          echo Math.ceil(10.234)
          Show
          grayaii Alex Gray added a comment - Not sure if this helps people, but as a workaround, you can run your script like so: java -jar jenkins-cli.jar -remoting -noCertificateCheck -i id_rsa -s JENKINS_URL groovy /tmp/my_script.groovy where /tmp/my_script.groovy contains: echo Math .ceil(10.234)
          Hide
          jglick Jesse Glick added a comment -

          Gabriel Konat & Julien Garcia Gonzalez your cases are likely different from that reported by Roy Tinker. There are a lot of reasons why script-security may fail to identify the Java method which some Groovy expression is intending to call. The original probably involved varargs; these newer ones perhaps involve double vs. float coercions.

          Show
          jglick Jesse Glick added a comment - Gabriel Konat & Julien Garcia Gonzalez your cases are likely different from that reported by Roy Tinker . There are a lot of reasons why script-security may fail to identify the Java method which some Groovy expression is intending to call. The original probably involved varargs; these newer ones perhaps involve double vs. float coercions.
          Hide
          sho_nig S H added a comment - - edited

          Hi,

          Got the same error when running a jenkins file in a pipeline job,
          Error: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified staticMethod java.lang.Math round java.math.BigDecimal

          **When running the same Jenkins file as a script, when the "sandbox" option is unchecked, I don't get this error.

          Show
          sho_nig S H added a comment - - edited Hi, Got the same error when running a jenkins file in a pipeline job, Error: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified staticMethod java.lang.Math round java.math.BigDecimal ** When running the same Jenkins file as a script , when the "sandbox" option is unchecked, I don't get this error.
          Hide
          abayer Andrew Bayer added a comment -

          At least as of script-security 1.41, I can't reproduce the original error from new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get("/some/path"))), so I'm closing this.

          For any other method calls that produce an unclassified staticMethod ... error, please open a new ticket.

          Show
          abayer Andrew Bayer added a comment - At least as of script-security 1.41, I can't reproduce the original error from new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get("/some/path"))) , so I'm closing this. For any other method calls that produce an unclassified staticMethod ... error, please open a new ticket.

            People

            • Assignee:
              Unassigned
              Reporter:
              pianoroy Roy Tinker
            • Votes:
              7 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: