Skip to content

Add proper error handling to findBy method in JdbcOAuth2AuthorizationService  #1579

Closed
@Suvink

Description

@Suvink

Describe the bug
I recently came across the java.lang.IllegalArgumentException in Authorization Code flow with JdbcOAuth2AuthorizationService. More info on the issue has been discussed in #397.

While investigating this issue, I could not identify the exact point that this error pops up and had to add debug points and struggle to identify the line that was failing.
Upon inspecting the code, I noticed in the findBy method, a try block is used without a catch block.

private OAuth2Authorization findBy(String filter, List<SqlParameterValue> parameters) {
	try (LobCreator lobCreator = getLobHandler().getLobCreator()) {
		PreparedStatementSetter pss = new LobCreatorArgumentPreparedStatementSetter(lobCreator,
					parameters.toArray());
		List<OAuth2Authorization> result = getJdbcOperations().query(LOAD_AUTHORIZATION_SQL + filter, pss, getAuthorizationRowMapper());
		return !result.isEmpty() ? result.get(0) : null;
	}
}

It would be easy to identify the error if we can have a catch block and handle this error properly.

To Reproduce
Please refer to #397.

Expected behavior
Handle the errors in findBy method with a catch block.

Sample

private OAuth2Authorization findBy(String filter, List<SqlParameterValue> parameters) {
	try (LobCreator lobCreator = getLobHandler().getLobCreator()) {
		PreparedStatementSetter pss = new LobCreatorArgumentPreparedStatementSetter(lobCreator,
					parameters.toArray());
		List<OAuth2Authorization> result = getJdbcOperations().query(LOAD_AUTHORIZATION_SQL + filter, pss, getAuthorizationRowMapper());
		return !result.isEmpty() ? result.get(0) : null;
	} catch (Exception e){
              ....handle the exception
    }
}

Reports that include a sample will take priority over reports that do not.
At times, we may require a sample, so it is good to try and include a sample up front.

Metadata

Metadata

Assignees

Labels

status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions