Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot correctly extend Credential class #246

Open
nescp opened this issue Jan 15, 2019 · 0 comments
Open

Cannot correctly extend Credential class #246

nescp opened this issue Jan 15, 2019 · 0 comments
Labels
type: question Request for information or clarification. Not an issue.

Comments

@nescp
Copy link

nescp commented Jan 15, 2019

Environment details

  • OS: Windows
  • Java version: java 8
  • google-oauth-java-client version: from 1.14.1-beta to the current version in master (2019/01/15)

Steps to reproduce

I would like to extend the class Credential (com.google.api.client.auth.oauth2.Credential) and to override the method:

boolean handleResponse(com.google.api.client.http.HttpRequest request, com.google.api.client.http.HttpResponse response,boolean supportsRetry)
Unfortunately, this method shares a lock in Credential with many other methods, there is no method to access it and the visibility of the attribute is private.
Nevertheless, the class mentions explicitly in the comments and documentation: "Subclasses may override".

How is the correct way to extend this class taking into account this lock?

I would like to force a refresh of the token when an error 400 is produced in very a very particular situation, besides the actual 401 so I think I should use the lock.

Besides this, HttpResponse is final so I cannot make an extension of this class to override the method getStatusCode neither and change the returned status code.

External references such as API reference guides used

https://github.com/googleapis/google-oauth-java-client/blob/master/google-oauth-client/src/main/java/com/google/api/client/auth/oauth2/Credential.java
https://developers.google.com/api-client-library/java/google-oauth-java-client/reference/1.20.0/com/google/api/client/auth/oauth2/Credential

Any additional information below

If the lock in Credential is not accessible from the classes that extend it, I think a template method that allows full override of the method should be available:

public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) {
	lock.lock();
		
	try {
		return templateHandleResponse(request, response, supportsRetry)
	} finally {
          lock.unlock();
	}
	return false;
}

@JustinBeckwith JustinBeckwith added triage me I really want to be triaged. 🚨 This issue needs some love. labels Jan 22, 2019
@sduskis sduskis added type: question Request for information or clarification. Not an issue. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants