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

Slave#createLauncher relies on autoboxing and can thrown NPE

    XMLWordPrintable

Details

    Description

      in hudson.model.Slave#createLauncher
      hudson.Launcher.RemoteLauncher#RemoteLauncher(TaskListener,VirtualChannel,boolean) is invoked using Computer.isUnix() as argument, which return a Boolean. Autoboxing let us do such thing, but can result in NPE.

      Attachments

        Issue Links

          Activity

            ndeloof Nicolas De Loof created issue -
            oleg_nenashev Oleg Nenashev made changes -
            Field Original Value New Value
            Labels newbie-friendly
            oleg_nenashev Oleg Nenashev added a comment -

            Not a real defect since IsUnix command does not return null. But it still makes sense to fix that.

            public Launcher createLauncher(TaskListener listener) throws IOException, InterruptedException {
                    if(channel==null)
                        return new LocalLauncher(listener);
                    else
                        return new RemoteLauncher(listener,channel,channel.call(new IsUnix()));
                }
            
                private static final class IsUnix extends MasterToSlaveCallable<Boolean,IOException> {
                    public Boolean call() throws IOException {
                        return File.pathSeparatorChar==':';
                    }
                    private static final long serialVersionUID = 1L;
                }
            
            oleg_nenashev Oleg Nenashev added a comment - Not a real defect since IsUnix command does not return null. But it still makes sense to fix that. public Launcher createLauncher(TaskListener listener) throws IOException, InterruptedException { if(channel==null) return new LocalLauncher(listener); else return new RemoteLauncher(listener,channel,channel.call(new IsUnix())); } private static final class IsUnix extends MasterToSlaveCallable<Boolean,IOException> { public Boolean call() throws IOException { return File.pathSeparatorChar==':'; } private static final long serialVersionUID = 1L; }
            oleg_nenashev Oleg Nenashev made changes -
            Assignee Oleg Nenashev [ oleg_nenashev ]
            oleg_nenashev Oleg Nenashev added a comment -

            We hit it in another logic branch. I will fix it

            oleg_nenashev Oleg Nenashev added a comment - We hit it in another logic branch. I will fix it
            oleg_nenashev Oleg Nenashev made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            oleg_nenashev Oleg Nenashev added a comment - https://github.com/jenkinsci/jenkins/pull/2923
            oleg_nenashev Oleg Nenashev made changes -
            Remote Link This issue links to "PR #2923 (Web Link)" [ 17152 ]
            oleg_nenashev Oleg Nenashev made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]

            Code changed in jenkins
            User: Oleg Nenashev
            Path:
            core/src/main/java/hudson/model/Slave.java
            http://jenkins-ci.org/commit/jenkins/78a42d5a4a5d545324c2d3230de6947e1ec8806e
            Log:
            JENKINS-38527 - Prevent NullPointerException in Slave#createLauncher() and add cause diagnostics (#2923)

            • JENKINS-38527 - Prevent NullPointerException in Slave#createLauncher() and add cause diagnostics

            The original issue comes from the isUnix() unboxing, but we can also get into an issue later if we pass a null Channel instance to the logic.
            This change adds some diagnostics which discovers potential root causes of such potential NPEs due to the race conditions with Computer reconnection

            • JENKINS-38527 - Also handle cases when Channel#isClosingOrClosed() as @stephenc suggested
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/src/main/java/hudson/model/Slave.java http://jenkins-ci.org/commit/jenkins/78a42d5a4a5d545324c2d3230de6947e1ec8806e Log: JENKINS-38527 - Prevent NullPointerException in Slave#createLauncher() and add cause diagnostics (#2923) JENKINS-38527 - Prevent NullPointerException in Slave#createLauncher() and add cause diagnostics The original issue comes from the isUnix() unboxing, but we can also get into an issue later if we pass a null Channel instance to the logic. This change adds some diagnostics which discovers potential root causes of such potential NPEs due to the race conditions with Computer reconnection JENKINS-38527 - Also handle cases when Channel#isClosingOrClosed() as @stephenc suggested
            oleg_nenashev Oleg Nenashev added a comment -

            The pull request has been merged towards 2.68. Marking as LTS candidate

            oleg_nenashev Oleg Nenashev added a comment - The pull request has been merged towards 2.68. Marking as LTS candidate
            oleg_nenashev Oleg Nenashev made changes -
            Resolution Fixed [ 1 ]
            Status In Review [ 10005 ] Resolved [ 5 ]
            oleg_nenashev Oleg Nenashev made changes -
            Labels newbie-friendly lts-candidate newbie-friendly
            olivergondza Oliver Gondža made changes -
            Labels lts-candidate newbie-friendly 2.60.3-fixed newbie-friendly

            Code changed in jenkins
            User: Oleg Nenashev
            Path:
            core/src/main/java/hudson/model/Slave.java
            http://jenkins-ci.org/commit/jenkins/c2163c5b3cb4a0c42cdc31cf404a82bcecb05082
            Log:
            JENKINS-38527 - Prevent NullPointerException in Slave#createLauncher() and add cause diagnostics (#2923)

            • JENKINS-38527 - Prevent NullPointerException in Slave#createLauncher() and add cause diagnostics

            The original issue comes from the isUnix() unboxing, but we can also get into an issue later if we pass a null Channel instance to the logic.
            This change adds some diagnostics which discovers potential root causes of such potential NPEs due to the race conditions with Computer reconnection

            • JENKINS-38527 - Also handle cases when Channel#isClosingOrClosed() as @stephenc suggested

            (cherry picked from commit 78a42d5a4a5d545324c2d3230de6947e1ec8806e)

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/src/main/java/hudson/model/Slave.java http://jenkins-ci.org/commit/jenkins/c2163c5b3cb4a0c42cdc31cf404a82bcecb05082 Log: JENKINS-38527 - Prevent NullPointerException in Slave#createLauncher() and add cause diagnostics (#2923) JENKINS-38527 - Prevent NullPointerException in Slave#createLauncher() and add cause diagnostics The original issue comes from the isUnix() unboxing, but we can also get into an issue later if we pass a null Channel instance to the logic. This change adds some diagnostics which discovers potential root causes of such potential NPEs due to the race conditions with Computer reconnection JENKINS-38527 - Also handle cases when Channel#isClosingOrClosed() as @stephenc suggested (cherry picked from commit 78a42d5a4a5d545324c2d3230de6947e1ec8806e)
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-23305 [ JENKINS-23305 ]
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-47455 [ JENKINS-47455 ]
            jamesdumay James Dumay made changes -
            Remote Link This issue links to "CloudBees Internal OSS-2328 (Web Link)" [ 18342 ]
            oleg_nenashev Oleg Nenashev made changes -
            Link This issue is duplicated by JENKINS-23305 [ JENKINS-23305 ]

            People

              oleg_nenashev Oleg Nenashev
              ndeloof Nicolas De Loof
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: