I'm going to implement custom JwtDecoder used in OAuth2 resource server.
In the research about default JwtDecoder behaviors, I found SupplierJwtDecoder that lazily initialize JWTDecoder.
What's the advantages of deferring initialization with delegate pattern. It also seems to cause synchronizing problems.
@Override
public Jwt decode(String token) throws JwtException {
if (this.delegate == null) {
synchronized (this.jwtDecoderSupplier) {
if (this.delegate == null) {
try {
this.delegate = this.jwtDecoderSupplier.get();
} catch (Exception ex) {
throw wrapException(ex);
}
}
}
}
return this.delegate.decode(token);
}