TokenEndpoint : Handling Null Pointer Exception
<p>I've tried requesting a code from my oauth2 server by executing this command through curl</p>

<pre><code> curl -X POST -k -vu clientapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "grant_type=authorization_code&amp;scope=read%20write&amp;client_secret=123456&amp;client_id=clientapp&amp;code=appcode&amp;redirect_uri=localhost:3000"
</code></pre>

<p>the response was </p>

<pre><code>* Adding handle: conn: 0x608860
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x608860) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8080 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
* Server auth using Basic with user 'clientapp'
&gt; POST /oauth/token HTTP/1.1
&gt; Authorization: Basic Y2xpZW50YXBwOjEyMzQ1Ng==
&gt; User-Agent: curl/7.30.0
&gt; Host: localhost:8080
&gt; Accept: application/json
&gt; Content-Length: 131
&gt; Content-Type: application/x-www-form-urlencoded
&gt;
* upload completely sent off: 131 out of 131 bytes
&lt; HTTP/1.1 400 Bad Request
&lt; Date: Mon, 16 May 2016 01:02:09 GMT
&lt; Access-Control-Allow-Credentials: true
&lt; Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT,DELETE
&lt; Access-Control-Max-Age: 3600
&lt; Access-Control-Allow-Headers: Authorization,Content-Disposition,Content-Description,Content-Type,Accept, X-Requested-With, remember-me
&lt; X-Content-Type-Options: nosniff
&lt; X-XSS-Protection: 1; mode=block
&lt; Cache-Control: no-cache, no-store, max-age=0, must-revalidate
&lt; Pragma: no-cache
&lt; Expires: 0
&lt; X-Frame-Options: DENY
&lt; Cache-Control: no-store
&lt; Pragma: no-cache
&lt; Content-Type: application/json;charset=UTF-8
&lt; Transfer-Encoding: chunked
* Server Jetty(9.2.14.v20151106) is not blacklisted
&lt; Server: Jetty(9.2.14.v20151106)
&lt;
{"error":"invalid_grant","error_description":"Invalid authorization code: appcode"}*
</code></pre>

<p>Upon checking my logs I have received this error.</p>

<pre><code>2016-05-16 09:26:43.826  INFO 9688 --- [tp1276746636-47] o.s.s.o.provider.endpoint.TokenEndpoint  : Handling error: NullPointerException, null
</code></pre>

<p>a gist of my configuration</p>

<pre><code>@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends
        AuthorizationServerConfigurerAdapter {

    @Value("${client.secret}")
    private String clientSecret;

    @Value("${client}")
    private String clientId;

    @Autowired
    private TokenStore tokenStore;

    @Autowired
    private JdbcAuthorizationCodeServices jdbcAuthorizationCodeServices;

    /**
     * By default,
     * it uses the JDBCUserDetails, we exposed our own authentication manager bean
     */
    @Autowired
    @Qualifier("authenticationManagerBean")
    private AuthenticationManager authenticationManager;

    @Autowired
    private UserDetailsService userDetailsService;

    @Autowired
    private JdbcClientDetailsService jdbcClientDetailsService;

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints)
            throws Exception {
        endpoints
                .tokenStore(this.tokenStore)
                .authenticationManager(this.authenticationManager)
                .authorizationCodeServices(this.jdbcAuthorizationCodeServices).userApprovalHandler(new DefaultUserApprovalHandler());
    }

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        security.allowFormAuthenticationForClients();
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.withClientDetails(jdbcClientDetailsService);
                /*.inMemory()
                .withClient(clientId)
                .authorizedGrantTypes("password", "refresh_token")
                .authorities("USER")
                .scopes("read", "write")
                .resourceIds(RESOURCE_ID)
                .secret(clientSecret);*/
    }

    @Bean
    @Primary
    public DefaultTokenServices tokenServices() {
        DefaultTokenServices tokenServices = new DefaultTokenServices();
        tokenServices.setSupportRefreshToken(true);
        tokenServices.setTokenStore(this.tokenStore);
        return tokenServices;
    }
}
</code></pre>