Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static invocation of Class.getName()

Tags:

java

spring

osgi

I stumbled upon the following code in NestedRuntimeException in org.springframework.core:

static {
    NestedExceptionUtils.class.getName();
}

What is the use of having such a block?

like image 717
Novice User Avatar asked May 15 '18 05:05

Novice User


1 Answers

It will eagerly load the NestedExceptionUtils class to avoid classloader deadlock. There was a bug reported (SPR-5607) "Non-trivial NestedRuntimeException.getMessage() can cause deadlocks on OSGi" and this is the solution for the same issue.

Edited:

It is mentioned also in the source code as a comment. For full source code docs please follow the link. Here is the part of the source code of NestedRuntimeException class.

static {
    // Eagerly load the NestedExceptionUtils class to avoid classloader deadlock
    // issues on OSGi when calling getMessage(). Reported by Don Brown; SPR-5607.
    NestedExceptionUtils.class.getName();
}
like image 100
Amit Bera Avatar answered Oct 13 '22 15:10

Amit Bera