jenkinsci / jenkinsci/script-security-plugin

[JENKINS-71056] Shared library Enum fails on valueOf

Open
#882 4 comments 0 reactions 0 assignees View on GitHub
component:script-security-plugin imported-jira-issue priority:major resolution:unresolved
Dominant language
Java
Stars
76
Forks
181
Avg merge
14h 55m
Merged PRs (30d)
3

Description

Hi, I'm trying to use this dead simple enum in a shared library:

package x.y.z

enum ProjectTypes {
python,
node
// workaround https://issue-redirect.jenkins.io/issue/33023
ProjectTypes() {}
}

but I'm hitting a ridiculous bunch of errors. This time I'm really desperate and didn't find any workaround.

The enum is placed in the library's /src directory and called from a method in a /vars script, that does type coercion from a string such as this, let's call it tripMine.groovy:

import x.y.z.ProjectTypes

def call(String projectTypeStr) {
return projectTypeStr as ProjectTypes
}

This is supposed to work thanks to enum's valueOf() static method, but if I call it from a basic scripted pipeline (where the library is included on the folder-level):

@​Library('my-library@​my-branch') _

node {
    stage('trip') {
        def trouble = tripMine('python')
    }
}

I get this exception back:

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such static method found: staticMethod x.y.z.ProjectTypes valueOf java.lang.Class java.lang.String 

This is the main trouble, but the fun continues.

The exception is from the script-security-plugin, I'm an admin, so I can easily whitelist that in the In-process script approval page, but yikes, it's not there. I found JENKINS-53700">JENKINS-53700, but that's why I abandoned the usual declarative pipeline and used the scripted one. Still no dice.

Next I tried to add the method to the enum:

static ProjectTypes valueOf(Class clazz, String str) {

return python
}

This time the execution passed (why?), but reimplementing the whole method defies the very reason I used enum in the first place.

 

Is there something sensible I can do to make this work? I've also found this "improvement" suggestion JENKINS-56948">JENKINS-56948, which looks quite like the same thing, but I don't believe that's an improvement material. Hope I'm right   Thanks a lot!

---
Originally reported by tlwhitec, imported from: Shared library Enum fails on valueOf


  • status: Open
  • priority: Major
  • component(s): script-security-plugin
  • resolution: Unresolved
  • votes: 1
  • watchers: 3
  • imported: 2025-12-09

Raw content of original issue

Hi, I'm trying to use this dead simple enum in a shared library:



package x.y.z

enum ProjectTypes {
python,
node
// workaround https://issues.jenkins.io/browse/JENKINS-33023
ProjectTypes() {}
}


but I'm hitting a ridiculous bunch of errors. This time I'm really desperate and didn't find any workaround.
The enum is placed in the library's /src directory and called from a method in a /vars script, that does type coercion from a string such as this, let's call it tripMine.groovy:



import x.y.z.ProjectTypes

def call(String projectTypeStr) {
return projectTypeStr as ProjectTypes
}


This is supposed to work thanks to enum's valueOf() static method, but if I call it from a basic scripted pipeline (where the library is included on the folder-level):



@Library('my-library@my-branch') _

node {
    stage('trip') {
        def trouble = tripMine('python')
    }
}


I get this exception back:



org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such static method found: staticMethod x.y.z.ProjectTypes valueOf java.lang.Class java.lang.String 


This is the main trouble, but the fun continues.

The exception is from the script-security-plugin, I'm an admin, so I can easily whitelist that in the In-process script approval page, but yikes, it's not there. I found JENKINS-53700, but that's why I abandoned the usual declarative pipeline and used the scripted one. Still no dice.

Next I tried to add the method to the enum:



static ProjectTypes valueOf(Class clazz, String str) {

return python
}


This time the execution passed (why?), but reimplementing the whole method defies the very reason I used enum in the first place.

 

Is there something sensible I can do to make this work? I've also found this "improvement" suggestion JENKINS-56948, which looks quite like the same thing, but I don't believe that's an improvement material. Hope I'm right   Thanks a lot!

  • environment: Jenkins 2.387.1, everything mostly a few weeks old.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.