NullPointerException stack trace not available without debug agent

前端 未结 3 495
北荒
北荒 2020-11-29 20:46

I have recently found a bug that causes a NullPointerException. The exception is caught and logged using a standard slf4j statement. Abridged code below:

for         


        
3条回答
  •  情深已故
    2020-11-29 21:30

    I can replicate this but it seems kind of weird that this would be happening in your Action somewhere.

    If you call setStackTrace with an empty array, that'll cause only the text to be shown.

     public class Fark {
       public static void main(String[] args) {
           try {
               Fark.throwMe(args.length != 0);
    
           }
           catch (Exception e) {
               e.printStackTrace();
           }
    
       }
    
         public static final void throwMe(boolean arg) throws Exception{
             Exception e = new NullPointerException();
             if (arg) {
               e.setStackTrace(new StackTraceElement[0]);
             }
             throw e;
         }
     }
    

    Running it....

    % java Fark
    java.lang.NullPointerException
            at Fark.throwMe(Fark.java:15)
            at Fark.main(Fark.java:5)
    
    % java Fark nothing
    java.lang.NullPointerException
    

提交回复
热议问题