mardi 3 septembre 2019

How to avoid NPE in gradle test from code line using Exception.printStackTrace

I have a class where in the constructor, we have to print stack trace. For this purpose we are creating a new Exception instance and printing stack trace using e.printStackTrace call. Problem is that there is a unit test invoking this constructor (its an inner class, so it uses JMockit's Deencapsulation.newInnerInstance call). Now, build/test are done using gradle and it is failing with this stack trace:

    java.lang.NullPointerException
        at org.gradle.internal.io.LineBufferingOutputStream.<init>(LineBufferingOutputStream.java:49)
        at org.gradle.internal.io.LineBufferingOutputStream.<init>(LineBufferingOutputStream.java:41)
        at org.gradle.internal.io.LineBufferingOutputStream.<init>(LineBufferingOutputStream.java:37)
        at org.gradle.internal.io.LinePerThreadBufferingOutputStream.getStream(LinePerThreadBufferingOutputStream.java:35)
        at org.gradle.internal.io.LinePerThreadBufferingOutputStream.println(LinePerThreadBufferingOutputStream.java:198)
        at java.lang.Throwable$WrappedPrintStream.println(Throwable.java:748)
        at java.lang.Throwable.printStackTrace(Throwable.java:655)
        at java.lang.Throwable.printStackTrace(Throwable.java:643)
        at java.lang.Throwable.printStackTrace(Throwable.java:634)
...

Looking for some workaround to avoid this NPE.

Aucun commentaire:

Enregistrer un commentaire