Skip to content

google-http-client-android 1.31+ Posix crash #906

Description

@adriancretu

com.google.api.client.util.store.FileDataStoreFactory.setPermissionsToOwnerOnly

uses PosixFilePermission
This class was added only in Android API 26. Running on lower API devices results in:

Fatal Exception: java.lang.NoClassDefFoundError
Failed resolution of: Ljava/nio/file/attribute/PosixFilePermission;
com.google.api.client.util.store.FileDataStoreFactory.setPermissionsToOwnerOnly

Crash happens when trying to store OAuth credentials and doing something trivial like

new FileDataStoreFactory(filesDir)

Maybe since the package releases as "Android-compatible" this should be documented?

Activity

  1. added
    semver: patchA minor bug fix or small change.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    type: docsImprovement to the documentation for an API.
    on Mar 13, 2020
  2. elharo commented on Mar 13, 2020

    @elharo
    Contributor

    This is the code. It probably needs to catch LinkageError too and possibly use reflection:

      static void setPermissionsToOwnerOnly(File file) throws IOException {
        Set permissions = new HashSet<PosixFilePermission>();
        permissions.add(PosixFilePermission.OWNER_READ);
        permissions.add(PosixFilePermission.OWNER_WRITE);
        permissions.add(PosixFilePermission.OWNER_EXECUTE);
        try {
          Files.setPosixFilePermissions(Paths.get(file.getAbsolutePath()), permissions);
        } catch (UnsupportedOperationException exception) {
          LOGGER.warning("Unable to set permissions for " + file
              + ", because you are running on a non-POSIX file system.");
        } catch (SecurityException exception) {
          // ignored
        } catch (IllegalArgumentException exception) {
          // ignored
        }
      }
    
  3. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.priority: p2Moderately-important priority. Fix may not be included in next release.semver: patchA minor bug fix or small change.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions