jenkins-cli: NPE when run a build with Based Matrix Security

12 views
Skip to first unread message

David BOISSIER

unread,
May 13, 2011, 5:44:41 PM5/13/11
to jenkin...@googlegroups.com
Dear all,

I currently experiment authentication with jenkins-cli in the intellij-jenkins-control-plugin. When I run some test with a local jenkins server set up with Security Based Matrix, I have a NPE :

java.lang.NullPointerException
    at hudson.util.CaseInsensitiveComparator.compare(CaseInsensitiveComparator.java:40)
    at hudson.util.CaseInsensitiveComparator.compare(CaseInsensitiveComparator.java:34)
    at java.util.TreeMap.getEntryUsingComparator(TreeMap.java:351)
    at java.util.TreeMap.getEntry(TreeMap.java:322)
    at java.util.TreeMap.get(TreeMap.java:255)
    at hudson.util.CopyOnWriteMap.get(CopyOnWriteMap.java:89)
    at hudson.model.Hudson.getItem(Hudson.java:2058)
    at hudson.model.AbstractProject.findNearest(AbstractProject.java:1913)
    at hudson.cli.handlers.AbstractProjectOptionHandler.parseArguments(AbstractProjectOptionHandler.java:54)
    at org.kohsuke.args4j.CmdLineParser.parseArgument(CmdLineParser.java:435)
    at hudson.cli.CLICommand.main(CLICommand.java:177)
    at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    ...


Here the code I wrote to test authentication:

    public static void main(String[] args) throws Exception{

        String hudsonHost = "http://localhost:8080/jenkins";

        CLI cli = new CLI(new URL(hudsonHost));

        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            cli.execute(Arrays.asList("login", "--username", "dboissier", "--password", "dboissier"), System.in, System.out, byteArrayOutputStream);
            cli.execute(Arrays.asList("build", "jenkins-control-plugin"), System.in, System.out, byteArrayOutputStream);
            System.out.println("byteArrayOutputStream = " + byteArrayOutputStream.toString());
        } finally {
            cli.close();
        }
    }


To quickly fix it, I just hack the CaseInsensitiveComparator class

public final class CaseInsensitiveComparator implements Comparator<String>, Serializable {
    public static final Comparator<String> INSTANCE = new CaseInsensitiveComparator();

    private CaseInsensitiveComparator() {}

    public int compare(String lhs, String rhs) {
        /* begin hack to fix the NPE */
        if (lhs == null) {
            System.err.println("lhs = " + lhs);
            return -1;
        }
        /* begin hack to fix the NPE */
        return lhs.compareToIgnoreCase(rhs);
    }

    private static final long serialVersionUID = 1L;
}


and after re-deploy the class in the local Jenkins web app and running a build I have the following message:

No such job 'jenkins-control-plugin' perhaps you meant null?
java -jar jenkins-cli.jar build args...
Starts a build, and optionally waits for a completion.
Aside from general scripting use, this command can be
used to invoke another job from within a build of one job.
With the -s option, this command changes the exit code based on
the outcome of the build (exit code 0 indicates a success.)
...

It seems Jenkins does not succeed to retrieve the job I would like to build.

Please note that this bug appears only on this security configuration (including Project Base Matrix extension) and I reproduced it from 1.409 to current build.

Thanks,

David
Reply all
Reply to author
Forward
0 new messages