Closed roma2341 closed 10 months ago
Hello @roma2341 , thanks for bringing this up. The latest version available for Admin Directory is in https://github.com/googleapis/google-api-java-client-services/tree/main/clients/google-api-services-admin/directory_v1/2.0.0 - I'm not aware of any fixes of this kind lately but it may be better to have the latest just in case.
The problem seems to occur when parsing the response from the authentication server - I'll take a look to that logic.
Regarding the replication example, how are the methods of the example code called? A full reproducer would be great to have.
edit: also, feel free to reach out to our support hub if you have a plan for faster response times
Here is their previous response, related to a problem with the Google API's (maybe it can help you, for me this answer was expected and useless):
Initially i created previous issue on Github: https://github.com/googleapis/google-api-java-client-services/issues/14823 But after a while i contacted google support:
Hello Anna, Just to set the right expectations, we don't have the proper tools and documentation to work with stack traces, however I went ahead as a best effort, and I was able to determine the following: For Gmail: The Java program threw an IllegalArgumentException with the message "key messages". The exception was thrown in the JsonParser class of the Google HTTP client library, which was being used by a Google Gmail service in the GoogleGmailService class. The stack trace also shows that the read method of the GmailBoxRESTController class was being executed when the exception occurred. It's hard to say exactly what's causing the exception without more context, but it looks like the JsonParser is failing to parse a JSON response from the Gmail API because it's missing a required key called "messages". It's possible that there's an issue with the request being sent to the Gmail API. For Calendar: The stack trace shows the sequence of method calls that led to the exception being thrown. At the top of the stack trace is the location where the exception was thrown, which appears to be in a JSON parser (com.google.api.client.json.JsonParser). The exception seems to indicate that there is a problem with a key named "items". It is possible that this key is missing, misspelled, or has an incorrect format. The code is likely attempting to parse a JSON response from an API call, and the response is not in the expected format. To resolve this issue, you should check the code that is making the API call and ensure that the key "items" is spelled correctly and is present in the JSON response. You should also ensure that the response is in the expected format. For Directory: The error message indicates that there is an illegal argument being passed into a method in the Java program. Specifically, it is indicating that there is an issue with the "emails" field of a user object in the Google API client for the Directory API. It appears that the value being passed in for the "emails" field is not of the expected type, which is causing the error. It is possible that the value being passed in is null, or is not in the correct format. To resolve this error, you will need to ensure that the value being passed in for the "emails" field is of the correct type and format, according to the requirements of the Directory API. You may need to consult the documentation to determine what the correct format is for this field. Just to set the right expectations again, please note the Google Workspace API team's primary focus is to guarantee the Google Workspace APIs functionality, and we don't have the actual ability to support app implementation, or code development. If all of the above doesn't solve this behavior, as I was requiring in my last email, please let me know about your desired outcome and an actual screenshot of any error message you may receive, or if you could record your screen while performing the steps you have mentioned and provide a more detailed explanation I would highly appreciate it, as this information stands to be mandatory for further investigation and if there's the case, to create an internal consult case with the higher-tier engineers. I will remain at your disposal in case you have any other doubts, inquiries or updates to share with me, one email away, so please do not hesitate to reach out to me, as it will be my pleasure to continue working with you. Have a lovely rest of your day! With many thanks and warm regards, Iulian Google Workspace Support
Unfortunately, the previous solution provided did not resolve the issue entirely. The perplexing aspect is that it intermittently functions without any problems before abruptly ceasing to work. If the data were incorrect, one would expect random failures, yet it consistently operates without issues for 2-3 days before stopping, sometimes even after just 5-6 hours. Initially, we suspected potential API limitations or insufficient RAM, but after conducting a benchmark, it performed smoothly. We even attempted to address the RAM concern by increasing its capacity, but that did not yield any improvement either. Since the option to suspend/unsuspend users is only available in the production environment, I cannot simply rewrite the code until it functions correctly. It's reminiscent of the previous issue we encountered with the Gmail API, which was somehow resolved several months ago by adding numerous synchronized keywords in certain places and rewriting other segments and updated google libraries. However, I am dissatisfied with the fact that the API client does not provide clear error messages, making it challenging to explain to clients why the Google integrations are not functioning as expected.
We utilize the GoogleAuthAdminSDKService in our Spring @RestController. While it may seem like a threading issue, I have thoroughly examined our codebase and verified that we are not sharing anything non-threadsafe in relation to the Google libraries. However, while working on other tasks involving Google APIs, I observed that the Gmail API, which is executed through @Scheduled tasks, frequently throws the error "Illegal argument: key: emails (or other)". It's important to note that we do not utilize @Scheduled tasks in our main product.
In our implementation, we retrieve the User using the Directory API. We make use of the setSuspended(true/false) method to modify the suspension status, and then we apply the patch using the same object. It's worth mentioning that we do not make any modifications to the "email" field during this process.
I also tried to enable logging:
@PostConstruct
private void enableLogging() {
Logger logger = Logger.getLogger(HttpTransport.class.getName());
logger.setLevel(Level.ALL);
logger.addHandler(new Handler() {
@Override
public void close() throws SecurityException {
}
@Override
public void flush() {
}
@Override
public void publish(LogRecord record) {
log.info(record.getMessage());
}
});
}
Just before encountering the error, we logged this JSON data (however, when attempting to parse it using com.google.api.client.json.JsonParser, everything appeared to be ok).":
`{
"kind": "admin#directory#user",
"id": "NOT_MATTER",
"etag": "\"NOT_MATTER\"",
"primaryEmail": "NOT_MATTER@NOT_MATTER",
"name": {
"givenName": "NOT_MATTER",
"familyName": "NOT_MATTER NOT_MATTER",
"fullName": "NOT_MATTER NOT_MATTER NOT_MATTER"
},
"isAdmin": false,
"isDelegatedAdmin": false,
"lastLoginTime": "2023-04-18T16:25:34.000Z",
"creationTime": "2022-10-24T02:33:56.000Z",
"agreedToTerms": true,
"suspended": true,
"suspensionReason": "ADMIN",
"archived": false,
"changePasswordAtNextLogin": false,
"ipWhitelisted": false,
"emails": [
{
"address": "NOT_MATTER@NOT_MATTER.com",
"primary": true
}
],
"languages": [
{
"languageCode": "en",
"preference": "preferred"
}
],
"customerId": "NOT_MATTER",
"orgUnitPath": "/NOT_MATTER",
"isMailboxSetup": true,
"isEnrolledIn2Sv": false,
"isEnforcedIn2Sv": false,
"includeInGlobalAddressList": true
}`
As i see from stacktrace it fails on this line:
var gUser = service.users().get(userEmail).execute();
Thanks for bringing up the other instances of this error. I take back my suspicion on the authentication logic.
It seems like the Json parser gets values of unexpected types. For example emails
is expected to be an array of objects as the one you posted in your last response, but the error in the first comment is that it expected collection or array type but got class java.lang.Object
.
While I can't imagine why all your clients would start failing similarly with unexpected value types, I can see that the error message itself is not helpful at all (e.g. from the other issue Caused by: java.lang.IllegalArgumentException: expected collection or array type but got java.util.List<com.google.api.client.googleapis.json.GoogleJsonError$ErrorInfo>
) (edit: note that we have JsonError
s that should be explained in the exception instead of just saying they are unexpected)
The error occurs here: https://github.com/googleapis/google-http-java-client/blob/223dfef05114bd64acaba5424ee6d6c44f9223b9/google-http-client/src/main/java/com/google/api/client/json/JsonParser.java#L887-L901
Which is caused by an argument check to confirm that emails
(in this issue) is actually an array
https://github.com/googleapis/google-http-java-client/blob/223dfef05114bd64acaba5424ee6d6c44f9223b9/google-http-client/src/main/java/com/google/api/client/json/JsonParser.java#L724-L729
cc: @blakeli0 - why would we using a custom JsonParser
instead of something like gson in the first place?
I will attempt to update all Google libraries as I suspect that the issue may be caused by conflicts between different versions of the libraries or dependencies. I will let you know in a couple of days whether it helped, but if it is indeed due to library versions, here are all the versions of libraries we are using now (I will update the libraries and recheck to see if the bug is resolved. However, I have doubts that the versions are the problem because only the admin-directory doesn't work sometime):
after I updated the libraries the error remained.
google-api-services-admin-directory: directory_v1-rev20230516-2.0.0 firebase-admin: 9.2.0 google-api-services-tasks: v1-rev20230401-2.0.0 google-api-services-fcm: v1-rev20230609-2.0.0 google-cloud-texttospeech: 2.21.0
Google support replied that they do not support debugging and code implementation.
@roma2341 We couldn't reproduce the issue so far. It's very likely that when the error happens, you get some strange response of an object as "emails". Is it possible to shorten the reproducing example, preferably just one main function?
Closing as we couldn't reproduce this. Please reopen if this is still an issue and preferably you could produce a shorten repro as mentioned in above comment.
Environment details
Steps to reproduce
Code example
Stack trace
External references such as API reference guides
Any additional information below
I frequently encounter this issue, which seems to occur randomly. The first consistent instance was when it occurred within the @scheduled task while adding email synchronization logic (gmail api). However, when I moved the code out of the @scheduled task, it worked fine. Unfortunately, the problem resurfaced when I added logic involving Admin SDK API calls, and now I'm unsure how to resolve it. The issue persists randomly and only goes away after restarting the application. We encountered issues when users of our CRM attempted to read their mail using the Gmail API. Unexpectedly, the API started throwing exceptions randomly, requiring us to restart the application to resolve the problem. Google libraries is barely usable because of this randomness, we are already thinking about migrating to other service provider. we use deprecated
com.google.api.client.googleapis.auth.oauth2.GoogleCredential
. could the problem be due to this? I tried to write test that suspends/unsuspends a lot of users, do it in parallel, but can't reproduce issue manually.Possible relates to this issue