Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException is thrown unless isRunning() is called first #268

Closed
bane73 opened this issue Jun 22, 2017 · 1 comment
Closed

NullPointerException is thrown unless isRunning() is called first #268

bane73 opened this issue Jun 22, 2017 · 1 comment
Labels
Milestone

Comments

@bane73
Copy link

bane73 commented Jun 22, 2017

Forgive me if I have missed some config detail that this would resolve, I also did scan through current issues and am not finding anything about this (which is curious to me).

v0.3.7

public static void main(String[] args) {
  
    JenkinsServer jks = new JenkinsServer("https://jenkins.mydomain.com", "username", "token");
    
    // SAD PATH
    try {
             jks.getVersion(); 
    } catch(Exception e) {
             /* java.lang.NullPointerException
	      * at com.offbytwo.jenkins.JenkinsServer.getVersion(JenkinsServer.java:104)
              */
    }

    // HAPPY PATH
    jks.isRunning();
    jks.getVersion();
    
}
@khmarbaise khmarbaise added the bug label Jul 20, 2017
@khmarbaise
Copy link
Member

Yeah unfortunately you are right...The point is to get the version there must be at least a single communication happen with the Jenkins server otherwise this information is not set...so this needs to be fixed...Simplest solution would be to call isRunning() inside getVersion()...

@khmarbaise khmarbaise added this to the Release 0.3.8 milestone Jul 20, 2017
khmarbaise added a commit that referenced this issue Jul 20, 2017
 o Prevent to produce an NPE if getVersion() called
   before the first communication. So we call isRunning()
   which makes the first communication and will transfer
   http headers which contain the version which will be read
   by JenkinsHttpClient.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants