Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ArithmeticException thrown without stack trace and without message

@Override
public StreamObserver<MdtDialoutArgs> mdtDialout(StreamObserver<MdtDialoutArgs> responseObserver) {

    return new StreamObserver<MdtDialoutArgs>() {

        @Override
        public void onError(Throwable t) {
            logger.warn( "Encountered error in mdtDialout");
        }

        @Override
        public void onCompleted() {
            responseObserver.onCompleted();
        }

        @Override
        public void onNext(MdtDialoutArgs arg0) {
           try {
                ....
                ....
                ...
          } catch (Exception e) {
               logger.error(e.getMessage(), e);
          }
     }

Above code throws a java.lang.ArithmeticException without stack trace and without message. I am not creating/throwing empty ArithmeticException in the try block. What java method call/code can throw java.lang.ArithmeticException without stack trace and without error message?

And Has any one seen an ArithmeticException in java with no message before? Log output:

null java.lang.ArithmeticException

like image 775
suresh Avatar asked Oct 16 '25 12:10

suresh


1 Answers

For some frequently thrown exceptions, JVM will make an optimization to hide the stack trace. When the server restart, the stack trace of this exception will show again.

Optimized version

java.lang.ArithmeticException: null

After restart

java.lang.ArithmeticException: / by zero at java.math.BigDecimal.divideAndRound(BigDecimal.java:4106) at java.math.BigDecimal.divide(BigDecimal.java:5153)

You can add VM option -XX:-OmitStackTraceInFastThrow to close this optimization.

like image 54
eip777 Avatar answered Oct 18 '25 01:10

eip777



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!