java.io.NotSerializableException: hudson.model.FreeStyleBuild in jenkins 1.466

1,371 views
Skip to first unread message

Mikael Petterson

unread,
May 31, 2012, 6:02:16 AM5/31/12
to jenkin...@googlegroups.com
Hi,
 
The following class gives the IOException ( see below):
 
/**
     * {@inheritDoc}
     */
    @Override public boolean perform(AbstractBuild<?, ?> build,
                                     Launcher launcher,
                                     final BuildListener listener)
    throws InterruptedException, IOException {
        PrintStream logger = listener.getLogger();
 
        logger.println("Qrank Reports Processing: START");
 
        Map<String, String> pattern = new HashMap();
 
        pattern.put(PluginImpl.FINDBUGS, getReportFindBugsFilenamePattern());
        pattern.put(PluginImpl.COBERTURA, getReportCoberturaFilenamePattern());
        pattern.put(PluginImpl.TESTNG, getReportTestNGFilenamePattern());
        pattern.put(PluginImpl.TARGET_PARSER,
                    getLogAntCompileTargetFilenamePattern());
        pattern.put(PluginImpl.TEST_PARSER,
                    getLogAntCompileTestFilenamePattern());
        pattern.put(PluginImpl.JUNIT, getReportJunitFilenamePattern());
 
    This line gives exception   --> TestResults report = build.getWorkspace().act(new DataCollector(pattern,
                                                                        logger,
                                                                        build));
 
        build.getActions().add(new QrankBuildAction(build, report));
        logger.println("Qrank Reports Processing: FINISH");
        return true;
    }
 
When I googled I found the following:
 
 
But it is fixed.
 
Any ideas?
 
Br,
 
//mike
 
ERROR: Publisher jenkins.plugins.qrank.QrankPublisher aborted due to exception
hudson.util.IOException2: remote file operation failed: /tmp/myuser/workspace/my_job at hudson.remoting.Channel@a8cb99:esekilxxen125
        at hudson.FilePath.act(FilePath.java:835)
        at hudson.FilePath.act(FilePath.java:821)
        at jenkins.plugins.qrank.QrankPublisher.perform(QrankPublisher.java:184)
        at hudson.tasks.BuildStepMonitor$2.perform(BuildStepMonitor.java:27)
        at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:710)
        at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:685)
        at hudson.model.Build$RunnerImpl.post2(Build.java:162)
        at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:632)
        at hudson.model.Run.run(Run.java:1463)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:239)
Caused by: java.io.IOException: Unable to serialize hudson.FilePath$FileCallableWrapper@13eedb9
        at hudson.remoting.UserRequest.serialize(UserRequest.java:166)
        at hudson.remoting.UserRequest.<init>(UserRequest.java:62)
        at hudson.remoting.Channel.call(Channel.java:645)
        at hudson.FilePath.act(FilePath.java:828)
        ... 11 more
Caused by: java.io.NotSerializableException: hudson.model.FreeStyleBuild
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
        at hudson.remoting.UserRequest._serialize(UserRequest.java:155)
        at hudson.remoting.UserRequest.serialize(UserRequest.java:164)
        ... 14 more
 
 

Mikael Petterson

unread,
Jun 5, 2012, 8:24:56 AM6/5/12
to jenkin...@googlegroups.com
Anyone who knows what the problem is?
 
When I run the code jenkin 1.466 on a jenkins without slaves it works fine. But when I run it with slaves I get this error.
 
I am not sure what I need to change.
 
Really need someone with more insight in Jenkins than me :-)
 
br,
 
//mike


From: jenkin...@googlegroups.com [mailto:jenkin...@googlegroups.com] On Behalf Of Mikael Petterson
Sent: den 31 maj 2012 12:02
To: jenkin...@googlegroups.com
Subject: java.io.NotSerializableException: hudson.model.FreeStyleBuild in jenkins 1.466

Mikael Petterson

unread,
Jun 5, 2012, 10:57:45 AM6/5/12
to jenkin...@googlegroups.com
I am using slave version
Slave.jar version: 2.13
 
br,
 
//Mike


From: jenkin...@googlegroups.com [mailto:jenkin...@googlegroups.com] On Behalf Of Mikael Petterson
Sent: den 5 juni 2012 14:25
To: jenkin...@googlegroups.com
Subject: RE: java.io.NotSerializableException: hudson.model.FreeStyleBuild in jenkins 1.466

Mads Nielsen

unread,
Jun 6, 2012, 2:20:00 AM6/6/12
to jenkin...@googlegroups.com
I don't think your PrintStream (logger) is serializable, have you tried declaring it transient or commenting it out of your code? I learned that when i started developing, every argument you pass into your .act() method must be serializable.

--

Mads Nielsen
Trainee and Wizard
Praqma A/S

Tel: +45 50 98 18 09
Mail: m...@praqma.net
web: www.praqma.net

Tilmeld dig Praqmas Nyhedsgruppe!

Christian Wolfgang

unread,
Jun 6, 2012, 3:08:10 AM6/6/12
to jenkin...@googlegroups.com
... Or you should pass the listener to the constructor of DataCollector and in the invoke method getLogger() from the listener.

Mikael Petterson

unread,
Jun 7, 2012, 10:05:06 AM6/7/12
to jenkin...@googlegroups.com
Hi,
 
I have tried the following:
 
- Removing logger. No difference.
- Declared it as transient. No difference.
 
Trace points out:
 
Caused by: java.io.NotSerializableException: hudson.model.FreeStyleBuild
But I am not sure how I can avoid this.
 
br,
 
//mike
 
 


From: jenkin...@googlegroups.com [mailto:jenkin...@googlegroups.com] On Behalf Of Christian Wolfgang
Sent: den 6 juni 2012 09:08
To: jenkin...@googlegroups.com
Subject: Re: java.io.NotSerializableException: hudson.model.FreeStyleBuild in jenkins 1.466

Christian Wolfgang

unread,
Jun 7, 2012, 3:40:57 PM6/7/12
to jenkin...@googlegroups.com
Ah, I see. You actually had two non-serializable objects. Your build isn't either, which the exception states: java.io.NotSerializableException: hudson.model.FreeStyleBuild

Mikael Petterson

unread,
Jun 8, 2012, 8:51:40 AM6/8/12
to jenkin...@googlegroups.com
Hi,
 
Serialization problem is now solved. Thanks for the help.
 
However ( is it not always something...) now I get the following in my DataCollector ( still a master-slave setup):
 
java.lang.NullPointerException
	at jenkins.plugins.myplugin.DataCollector.findFiles(DataCollector.java:233)
	at jenkins.plugins.myplugin.DataCollector.doExtract(DataCollector.java:115)
	at jenkins.plugins.myplugin.DataCollector.invoke(DataCollector.java:90)
	at jenkins.plugins.qrank.DataCollector.invoke(DataCollector.java:35)
	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2177)
	at hudson.remoting.UserRequest.perform(UserRequest.java:118)
	at hudson.remoting.UserRequest.perform(UserRequest.java:48)
	at hudson.remoting.Request$2.run(Request.java:287)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
It is confusing when I see it working in the standalone installation but when I install it in my
master-slave installation I get the above error.
I appreciate all pointers.
//mike
This is the code I am using:
 
/**
 *
 */
package jenkins.plugins.qrank;
 
import hudson.FilePath;
 
import hudson.FilePath.FileCallable;
 
import hudson.model.AbstractBuild;
 
import hudson.remoting.VirtualChannel;
 
import jenkins.plugins.qrank.parse.LogParser;
import jenkins.plugins.qrank.parse.PullParserFactory;
import jenkins.plugins.qrank.parse.TestResults;
 
import org.apache.tools.ant.types.FileSet;
 
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
 
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
 
/**
 * This class collects all data and returns it to the caller.
 *
 * @author mikael petterson
 *
 */
public class DataCollector implements FileCallable<TestResults> {
    /**
     *
     */
    private static final long serialVersionUID = 5174278843704513371L;
 
    private static final String[] NO_FILE = new String[] {};
 
    private static final String[] TARGET = new String[] {
            PluginImpl.BUILD_ON_TARGET_NO_ERR,
            PluginImpl.BUILD_ON_TARGET_NO_WARN }; // Order is important!
 
    private static final String[] TEST = new String[] {
            PluginImpl.BUILD_FOR_TEST_NO_ERR, PluginImpl.BUILD_FOR_TEST_NO_WARN }; // Order
                                                                                   // is
                                                                                   // important!
 
    private static final String[] PATTERNS = new String[] {
            "\\s*\\[javac\\]\\s{1}\\d+\\serror|errors",
            "\\s*\\[javac\\]\\s{1}\\d+\\swarning|warnings" }; // Order is
                                                              // important!
 
    private final Map<String, String> pattern;
 
    private final transient PrintStream logger;
 
    private transient File workspace;
 
    private final transient AbstractBuild<?, ?> build;
 
    public DataCollector(final Map<String, String> pattern,
            final PrintStream logger, final AbstractBuild<?, ?> build) {
        this.pattern = pattern;
        this.logger = logger;
        this.build = build;
    }
 
    /**
     * Collects data and returns the result to the caller.
     */
    public TestResults invoke(final File workspace, final VirtualChannel channel)
            throws IOException, InterruptedException {
        this.workspace = workspace;
 
        final TestResults report = new TestResults();
 
        for (Map.Entry<String, String> entry : pattern.entrySet()) {
            final String pattern = entry.getValue();
 
            if (pattern == null) {
                logger.println("Pattern for type " + entry.getKey()
                        + " is null");
                continue;
            }
 
            doExtract(entry.getKey(), pattern, report);
        }
 
        report.calcQrank();
        return report;
    }
 
    /**
     * Finds the files using patterns ( exception cobertura) and calls diff-
     * erent parsers.
     *
     * @param type
     * @param pattern
     * @param report
     * @throws IOException
     */
    private void doExtract(final String type, final String pattern,
            final TestResults report) throws IOException {
        String[] fileNames;
 
        if (type.equals(PluginImpl.COBERTURA)) {
            fileNames = getCoberturaXml(pattern);
        } else {
            // Files in workspace.
            if (pattern.length() != 0 && workspace != null) {
115:                fileNames = findFiles(workspace, pattern);
            } else {
                fileNames = new String[] {};
            }
        }
 
        if (fileNames.length == 0) {
            logger.println("No report/log files of type " + type
                    + " with pattern " + pattern + " were found!");
            return;
        }
        for (int i = 0; i < fileNames.length; i++) {
            logger.println("File to be parsed: " + fileNames[i]);
        }
 
        for (String fileName : fileNames) {
            final File file;
            Map<String, Pattern> patternsMap;
 
            if (type.equals(PluginImpl.TARGET_PARSER)) {
                patternsMap = preparePatterns(TARGET);
                file = new File(workspace, fileName);
                parseAntLog(file, patternsMap, report);
            } else if (type.equals(PluginImpl.TEST_PARSER)) {
                patternsMap = preparePatterns(TEST);
                file = new File(workspace, fileName);
                parseAntLog(file, patternsMap, report);
            } else if (type.equals(PluginImpl.COBERTURA)) {
                file = new File(fileName);
                PullParserFactory.instance().createParser(type)
                        .parse(file, type, report);
            } else {
                file = new File(workspace, fileName);
                PullParserFactory.instance().createParser(type)
                        .parse(file, type, report);
            }
        }
    }
 
    // TODO: add handking when cobertura file is not found.
    private String[] getCoberturaXml(String pattern) {
        logger.println("Retrieving Cobertura coverage report...");
 
        final FilePath[] moduleRoots = build.getModuleRoots();
        final boolean multipleModuleRoots = (moduleRoots != null)
                && (moduleRoots.length > 1);
        final FilePath moduleRoot = multipleModuleRoots ? build.getWorkspace()
                : build.getModuleRoot();
        final File buildCoberturaDir = build.getRootDir();
        FilePath buildTarget = new FilePath(buildCoberturaDir);
 
        FilePath[] reports = new FilePath[0];
 
        try {
            reports = moduleRoot.list(pattern);
        } catch (IOException e) {
            logger.println("Unable to find file " + pattern);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
 
        String[] filesFound = new String[reports.length];
 
        for (int i = 0; i < reports.length; i++) {
            filesFound[i] = reports[i].getRemote();
        }
 
        return filesFound;
    }
 
    /**
     * Sets the patterns to the ant log parser.
     *
     * @param types
     * @return patternsMap a map with type and accompanying pattern.
     */
    private Map<String, Pattern> preparePatterns(final String[] types) {
        final Map<String, Pattern> patternsMap = new HashMap<String, Pattern>();
 
        for (int i = 0; i < types.length; i++) {
            patternsMap.put(types[i], Pattern.compile(PATTERNS[i]));
        }
 
        return patternsMap;
    }
 
    /**
     * Calls the LogParser with regular expression used for parsing ant build
     * file output.
     *
     * @param file
     *            log file
     * @param patternsMap
     *            map containing type and regexp.
     * @param report
     *            test result.
     * @throws IOException
     */
    private void parseAntLog(final File file,
            final Map<String, Pattern> patternsMap, final TestResults report)
            throws IOException {
        final InputStream is = new java.io.FileInputStream(file);
        final LogParser logParser = new LogParser();
 
        logParser.parse(is, report, patternsMap);
    }
 
    /**
     * Returns an array with the filenames of the files that match an Ant
     * pattern using the workspace as the base directory.
     *
     * @param workspaceRoot
     *            root directory of the workspace
     *
     * @return the filenames found.
     */
    private String[] findFiles(final File workspaceRoot, final String pattern) {
        logger.println("find files in " + workspaceRoot + " pattern " + pattern);
 
        String[] files;
 
        if (isBlank(pattern)) {
            files = new String[] {};
        } else {
            final FileSet fileSet = new FileSet();
            final org.apache.tools.ant.Project project = new org.apache.tools.ant.Project();
 
            fileSet.setProject(project);
            fileSet.setDir(workspaceRoot);
            fileSet.setIncludes(pattern);
 
            files = fileSet.getDirectoryScanner(project).getIncludedFiles();
        }
 
        return files;
    }
 
    /**
     * Check if the string is null or only spaces.
     *
     * @param str
     *            the string to test.
     * @return true if string is null or all spaces.
     */
    public static boolean isBlank(final String str) {
        return (str == null) ? true : "".equals(str.trim());
    }
}

 

From: jenkin...@googlegroups.com [mailto:jenkin...@googlegroups.com] On Behalf Of Christian Wolfgang
Sent: den 7 juni 2012 21:41
Reply all
Reply to author
Forward
0 new messages