Windows build fails with java.lang.RuntimeException: Failed to serialize hudson.model.Project

33 views
Skip to first unread message

jsupun

unread,
Nov 12, 2021, 4:09:27 PM11/12/21
to Jenkins Developers
For the ci.jenkins.io Windows build, for a test I'm getting a failure of

    14:12:17 java.lang.RuntimeException: java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.Project#buildWrappers for class hudson.model.FreeStyleProject
    14:12:17 at hudson.util.PersistedList._onModified(PersistedList.java:214) 
    14:12:17 at hudson.util.PersistedList.add(PersistedList.java:80) 14:12:17 at io.jenkins.plugins.ksm.builder.KsmBuildWrapperTest.testBuilder(KsmBuildWrapperTest.java:210)

Which is basically me adding my BuildWrapper to a project's wrappers in a test.

    project.getBuildWrappersList().add(buildWrapper);

Locally under Windows and Linux, I do not get this errors for the test. And even the ci.jenkins.io Linux build doesn't have this problem. 

I've tried adding implements Serializable to the class, and adding the problem classes to META-INF/hudson.remoting.ClassFilter as an attempt to get it working with no luck. Spitballing.

I normally don't do Java development so I'm kind of lost on why my tests work in some environments and not others.

Thanks,
John


Daniel Beck

unread,
Nov 12, 2021, 4:21:27 PM11/12/21
to jenkin...@googlegroups.com
On Fri, Nov 12, 2021 at 10:09 PM 'jsupun' via Jenkins Developers <jenkin...@googlegroups.com> wrote:
For the ci.jenkins.io Windows build, for a test I'm getting a failure of

    14:12:17 java.lang.RuntimeException: java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.Project#buildWrappers for class hudson.model.FreeStyleProject
    14:12:17 at hudson.util.PersistedList._onModified(PersistedList.java:214) 
    14:12:17 at hudson.util.PersistedList.add(PersistedList.java:80) 14:12:17 at io.jenkins.plugins.ksm.builder.KsmBuildWrapperTest.testBuilder(KsmBuildWrapperTest.java:210)


Java exceptions are structured so that the relevant part is further down.

In this case,
Caused by: java.lang.RuntimeException: Failed to serialize io.jenkins.plugins.ksm.builder.KsmBuildWrapper#consoleLogger for class io.jenkins.plugins.ksm.builder.TestWrapper
(plus more details, but this identifies the problem in your code)

You have a field you should mark transient and re-create in a protected readResolve method: https://docs.oracle.com/javase/8/docs/platform/serialization/spec/input.html#a5903 
Alternatively, restructure your code so this isn't a field of your class.

If anyone else wants to take a look, the plugin is https://github.com/jenkinsci/keeper-secrets-manager-plugin
(As general advice, it's more likely that others are able to help you if you provide a reference to the source code causing problems.)

Jesse Glick

unread,
Nov 15, 2021, 8:57:03 AM11/15/21
to jenkin...@googlegroups.com
On Fri, Nov 12, 2021 at 4:21 PM 'Daniel Beck' via Jenkins Developers <jenkin...@googlegroups.com> wrote:
restructure your code so this isn't a field of your class.

Do that. https://github.com/jenkinsci/keeper-secrets-manager-plugin/blob/870ee7ee7c26df6877cb78b7831511db89974c72/src/main/java/io/jenkins/plugins/ksm/builder/KsmBuildWrapper.java#L24 is not correct. A `TaskListener` will be passed to methods which require it; pass it along to any other methods you call in turn which might require it. Do not try to save it as a field. 

jsupun

unread,
Nov 15, 2021, 10:29:51 AM11/15/21
to Jenkins Developers
Well that was the problem. Easy fix since apparently it wasn't being used anyplace :/ A relic from a refactoring. Delete it and all tests pass now in CI. Thanks all.
Reply all
Reply to author
Forward
0 new messages