java.lang.NullPointerException

Jenkins JIRA | Anders Engqvist | 3 years ago
  1. 0

    When using Jenkins CLI, I get the following exception: {code} Exception in thread "main" java.lang.NullPointerException at hudson.cli.CLI.flushURLConnection(CLI.java:310) at hudson.cli.CLI.getCliTcpPort(CLI.java:285) at hudson.cli.CLI.<init>(CLI.java:134) at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72) at hudson.cli.CLI._main(CLI.java:469) at hudson.cli.CLI.main(CLI.java:384) {code} The code where the exception is thrown looks like this: {code} 299 private void flushURLConnection(URLConnection conn) { 300 byte[] buf = new byte[1024]; 301 try { 302 InputStream is = conn.getInputStream(); 303 while (is.read(buf) >= 0) { 304 // Ignore 305 } 306 is.close(); 307 } catch (IOException e) { 308 try { 309 InputStream es = ((HttpURLConnection)conn).getErrorStream(); 310 while (es.read(buf) >= 0) { 311 // Ignore 312 } 313 es.close(); 314 } catch (IOException ex) { 315 // Ignore 316 } 317 } 318 } {code} It seems that es is null, the documentation for getErrorStream states: {code} public InputStream getErrorStream() Returns: an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data. {code} A solution is just to add a check for null before reading from the stream. But maybe there is some deeper problem here because the NullPointerException occurs in a catch block of an IOException. But output from both the input stream and error stream is ignored so perhaps it is nothing to worry about? The CLI is used from jobs in Jenkins, so this cause builds to fail. It is only on some nodes this is happening so the root cause is probably an environment issue because using the CLI has worked before.

    Jenkins JIRA | 3 years ago | Anders Engqvist
    java.lang.NullPointerException
  2. 0

    When using Jenkins CLI, I get the following exception: {code} Exception in thread "main" java.lang.NullPointerException at hudson.cli.CLI.flushURLConnection(CLI.java:310) at hudson.cli.CLI.getCliTcpPort(CLI.java:285) at hudson.cli.CLI.<init>(CLI.java:134) at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72) at hudson.cli.CLI._main(CLI.java:469) at hudson.cli.CLI.main(CLI.java:384) {code} The code where the exception is thrown looks like this: {code} 299 private void flushURLConnection(URLConnection conn) { 300 byte[] buf = new byte[1024]; 301 try { 302 InputStream is = conn.getInputStream(); 303 while (is.read(buf) >= 0) { 304 // Ignore 305 } 306 is.close(); 307 } catch (IOException e) { 308 try { 309 InputStream es = ((HttpURLConnection)conn).getErrorStream(); 310 while (es.read(buf) >= 0) { 311 // Ignore 312 } 313 es.close(); 314 } catch (IOException ex) { 315 // Ignore 316 } 317 } 318 } {code} It seems that es is null, the documentation for getErrorStream states: {code} public InputStream getErrorStream() Returns: an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data. {code} A solution is just to add a check for null before reading from the stream. But maybe there is some deeper problem here because the NullPointerException occurs in a catch block of an IOException. But output from both the input stream and error stream is ignored so perhaps it is nothing to worry about? The CLI is used from jobs in Jenkins, so this cause builds to fail. It is only on some nodes this is happening so the root cause is probably an environment issue because using the CLI has worked before.

    Jenkins JIRA | 3 years ago | Anders Engqvist
    java.lang.NullPointerException
  3. 0

    Android: Saving Map State in Google map

    Stack Overflow | 11 months ago | Junie Negentien
    java.lang.RuntimeException: Unable to resume activity {com.ourThesis.junieNegentien2015/com.ourThesis.junieNegentien2015.MainActivity}: java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at hudson.cli.CLI.flushURLConnection()
    2. Hudson
      CLI.main
      1. hudson.cli.CLI.flushURLConnection(CLI.java:310)
      2. hudson.cli.CLI.getCliTcpPort(CLI.java:285)
      3. hudson.cli.CLI.<init>(CLI.java:134)
      4. hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72)
      5. hudson.cli.CLI._main(CLI.java:469)
      6. hudson.cli.CLI.main(CLI.java:384)
      6 frames