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

Upload the file to the Keeper record using Java/Kotlin SDK causes exception "null cannot be cast to non-null type com.keepersecurity.secretsManager.core.FileRef" #698

Open
tszielin opened this issue Jan 3, 2025 · 2 comments

Comments

@tszielin
Copy link

tszielin commented Jan 3, 2025

Cannot upload the file to the Keeper's record using Java/Kotlin SDK

Steps to reproduce:

  • create the empty "file" record in Keeper.
  • run an example from the documentation page Upload a File Attachment with set the UID to created empty record in code
    // create a filter with the UID of the record we want
    List<String> uidFilter = List.of("XXX");

The application throws an error null cannot be cast to non-null type com.keepersecurity.secretsManager.core.FileRef and no file is appended to record.

@maksimu
Copy link
Collaborator

maksimu commented Jan 4, 2025

Hello @tszielin
This is interesting bug. For now you will need to make ensure record has FileRef field initialized with the following code, before SecretsManager.uploadFile() call add following:

if (ownerRecord.getData().getField(FileRef.class) == null) {
    // Initialize FileRef with empty list if it doesn't exist
    FileRef fileRef = new FileRef(new ArrayList<>());
    ownerRecord.getData().getFields().add(fileRef);
}

This quick hack should fix it. We will update our SDK to handle this case in the next release.

Thank you,

Max

maksimu added a commit that referenced this issue Jan 4, 2025
Replace unsafe cast (as T) with safe cast operator (as? T) in getField()
to prevent NPE when uploading files to records without FileRef field.

This fixes an issue where attempting to upload a file to a record
without an initialized FileRef field would throw:
"null cannot be cast to non-null type FileRef"

Fixes #698
@tszielin
Copy link
Author

tszielin commented Jan 5, 2025

Hello @maksimu

The workaround is working. Many thanks for response. Waiting for the release with fix.

Thank you,
Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants