#vulnerable code 
                             @Override
	public Object handle(HttpExchange x) throws Exception {
		String code = x.param("code");
		String state = x.param("state");

		U.debug("Received OAuth code", "code", code, "state", state);

		if (code != null && state != null) {
			U.must(stateCheck.isValidState(state, clientSecret, x.sessionId()), "Invalid OAuth state!");

			String redirectUrl = oauthDomain != null ? oauthDomain + callbackPath : x.constructUrl(callbackPath);

			TokenRequestBuilder reqBuilder = OAuthClientRequest.tokenLocation(provider.getTokenEndpoint())
					.setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(clientId).setClientSecret(clientSecret)
					.setRedirectURI(redirectUrl).setCode(code);

			OAuthClientRequest request = paramsInBody() ? reqBuilder.buildBodyMessage() : reqBuilder.buildBodyMessage();

			OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

			String accessToken = token(request, oAuthClient);

			String profileUrl = U.fillIn(provider.getProfileEndpoint(), "token", accessToken);

			OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(profileUrl).setAccessToken(
					accessToken).buildQueryMessage();

			OAuthResourceResponse res = oAuthClient.resource(bearerClientRequest,
					org.apache.oltu.oauth2.common.OAuth.HttpMethod.GET, OAuthResourceResponse.class);

			U.must(res.getResponseCode() == 200, "OAuth response error!");

			Map<String, Object> auth = JSON.parseMap(res.getBody());

			String firstName = (String) U.or(auth.get("firstName"),
					U.or(auth.get("first_name"), auth.get("given_name")));
			String lastName = (String) U.or(auth.get("lastName"), U.or(auth.get("last_name"), auth.get("family_name")));

			UserInfo user = new UserInfo();

			user.name = U.or((String) auth.get("name"), firstName + " " + lastName);
			user.oauthProvider = provider.getName();
			user.email = (String) U.or(auth.get("email"), auth.get("emailAddress"));
			user.username = user.email;
			user.oauthId = String.valueOf(auth.get("id"));
			user.display = user.email.substring(0, user.email.indexOf('@'));

			x.sessionSet("_user", user);
			U.must(x.user() == user);

			return x.redirect("/");
		} else {
			String error = x.param("error");
			if (error != null) {
				U.warn("OAuth error", "error", error);
				throw U.rte("OAuth error!");
			}
		}

		throw U.rte("OAuth error!");
	} 
                            #location 46 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                             @Override
	public Object handle(HttpExchange x) throws Exception {
		String code = x.param("code");
		String state = x.param("state");

		U.debug("Received OAuth code", "code", code, "state", state);

		if (code != null && state != null) {
			U.must(stateCheck.isValidState(state, clientSecret, x.sessionId()), "Invalid OAuth state!");

			String redirectUrl = oauthDomain != null ? oauthDomain + callbackPath : x.constructUrl(callbackPath);

			TokenRequestBuilder reqBuilder = OAuthClientRequest.tokenLocation(provider.getTokenEndpoint())
					.setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(clientId).setClientSecret(clientSecret)
					.setRedirectURI(redirectUrl).setCode(code);

			OAuthClientRequest request = paramsInBody() ? reqBuilder.buildBodyMessage() : reqBuilder.buildBodyMessage();

			OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

			String accessToken = token(request, oAuthClient);

			String profileUrl = U.fillIn(provider.getProfileEndpoint(), "token", accessToken);

			OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(profileUrl).setAccessToken(
					accessToken).buildQueryMessage();

			OAuthResourceResponse res = oAuthClient.resource(bearerClientRequest,
					org.apache.oltu.oauth2.common.OAuth.HttpMethod.GET, OAuthResourceResponse.class);

			U.must(res.getResponseCode() == 200, "OAuth response error!");

			Map<String, Object> auth = JSON.parseMap(res.getBody());

			String firstName = (String) U.or(auth.get("firstName"),
					U.or(auth.get("first_name"), auth.get("given_name")));
			String lastName = (String) U.or(auth.get("lastName"), U.or(auth.get("last_name"), auth.get("family_name")));

			UserInfo user = new UserInfo();

			user.name = U.or((String) auth.get("name"), firstName + " " + lastName);
			user.oauthProvider = provider.getName();
			user.email = (String) U.or(auth.get("email"), auth.get("emailAddress"));
			user.username = user.email;
			user.oauthId = String.valueOf(auth.get("id"));

			x.sessionSet("_user", user);
			U.must(x.user() == user);

			return x.redirect("/");
		} else {
			String error = x.param("error");
			if (error != null) {
				U.warn("OAuth error", "error", error);
				throw U.rte("OAuth error!");
			}
		}

		throw U.rte("OAuth error!");
	}