question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NullPointerException: Cannot invoke "java.io.InputStream.available()" because "this.val$is" is null

See original GitHub issue

Hi there, I’ve got the the following error using the following example in https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/kubectl/equivalents/PodExecEquivalent.java

2021-11-10 14:50:13,115 ERROR [io.fab.kub.cli.uti.InputStreamPumper] (pool-16-thread-1) Error while pumping stream.: java.lang.NullPointerException: Cannot invoke "java.io.InputStream.available()" because "this.val$is" is null
	at io.fabric8.kubernetes.client.utils.InputStreamPumper$1.read(InputStreamPumper.java:53)
	at io.fabric8.kubernetes.client.utils.InputStreamPumper.transferTo(InputStreamPumper.java:76)
	at io.fabric8.kubernetes.client.utils.InputStreamPumper.lambda$pump$0(InputStreamPumper.java:89)
	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

Here is my code:

class Foo{
    val execLatch = CountDownLatch(1);
    private val LOG: Logger = LoggerFactory.getLogger(Foo::class.java)

    fun doSomething(): Unit {
        val out = ByteArrayOutputStream()
        val error = ByteArrayOutputStream()

        val execWatch = kubernetesClient.pods()
            .inNamespace(kubernetesClient.namespace)
            .withName("MY-POD")
            .inContainer("MY-CONTAINER")
            .writingOutput(out)
            .writingError(error)
            .usingListener(MyPodExecListener())
            .exec("du", "-s", "/home/abcd")

        val latchTerminationStatus: Boolean = execLatch.await(5, TimeUnit.SECONDS)
        if (!latchTerminationStatus) {
            LOG.warn("Latch could not terminate within specified time")
        }
        LOG.info("Exec Output: {} ", out)
        execWatch.close()
    }

    inner class MyPodExecListener : ExecListener {

        override fun onOpen(response: okhttp3.Response?) {
            println(response)
            LOG.info("Shell was opened")
        }

        override fun onFailure(t: Throwable?, response: okhttp3.Response?) {
            LOG.info("Some error encountered")
            execLatch.countDown()
        }

        override fun onClose(i: Int, s: String) {
            LOG.info("Shell Closing")
            execLatch.countDown()
        }
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shawkinscommented, Nov 10, 2021

Should be a duplicate of #3384

1reaction
shawkinscommented, Nov 10, 2021

Perhaps something related to this topic, If I call the endpoint/method. At first run it shows the output in afterwards it doesnt:

It’s not related to the NPE. I’m not sure if there is a trace level for websocket traffic, if you can’t seem to get a log can you put breakpoints in ExecWebSocketListener.onMessage and cleanUpOnce to see if you are getting a message prior to the websocket being closed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - InputStream.available() generating Null pointer exception
I'm trying to build an HTTP server, I searched the net to solve this problem, but I did not find anything like that....
Read more >
throw NPE when copy file from pod to local #3384 - GitHub
NullPointerException : Cannot invoke "java.io.InputStream.available()" because "this.val$is" is null at io.fabric8.kubernetes.client.utils.
Read more >
How to use available method in java.io.InputStream - Tabnine
Reads all available bytes from InputStream as a byte array. * Uses <code>in.available()</code> to determine the size of input stream.
Read more >
Example usage for java.io InputStream available - Java2s.com
Document. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which...
Read more >
java .lang.nullpointerexception Code Example - Code Grepper
NullPointerException : Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null · Integrity check failed: java.security.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found