eclipse-vertx/vertx-auth

NullPointerException in private Constructor of OAuth2AuthHandlerImpl

fbuetler opened this issue · 1 comments

Version

I encountered the issue with vertx-auth-oauth2 4.3.7 but also with the latest master commit.

Context

I encountered a NullPointerException while using the following code snippet:

final OAuth2AuthHandler authHandler = OAuth2AuthHandler.create(vertx, authProvider, callbackURL)
        .setupCallback(callback)
        .extraParams(responseModeParam)
        .withScope(sessionScope);

The withScope call triggers the creation of a new OAuth2AuthHandlerImpl with a private constructor.
Note, that some extraParams are set beforehand.
In the private constructor the extraParams are copied, but obviously trigger a NullPointerException:

// state copy
    if (base.extraParams != null) {
      extraParams = extraParams.copy();
    }

Start of the stack trace:

20:03:39.348 [vert.x-eventloop-thread-0] ERROR io.vertx.core.impl.ContextBase - Unhandled exception
java.lang.NullPointerException: null
        at io.vertx.ext.web.handler.impl.OAuth2AuthHandlerImpl.<init>(OAuth2AuthHandlerImpl.java:111)
        at io.vertx.ext.web.handler.impl.OAuth2AuthHandlerImpl.withScope(OAuth2AuthHandlerImpl.java:244)

Proposed Fix

// state copy
    if (base.extraParams != null) {
      extraParams = base.extraParams.copy();
    }

Mitigation

Put the extraParams() at the end such that the path triggering the Exception in the private constructor is not used.

My bad, wrong repo. Moved to vertx-web