static invocation of Class.getName()

  • A+
Category:Languages

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?


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(); } 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: