Skip to content

[getObject] NoSuchKeyException is not thrown when key does not exist AND a versionId is provided #2235

Closed
@scotty-g

Description

@scotty-g

Describe the bug

When calling S3Client#getObject(GetObjectRequest) there is different behavior for the error thrown depending on whether a version is provided or not.

For example, on a versioned bucket

  • Providing only a key and no versionId results in NoSuchKeyException: The specified key does not exist.
  • Providing both a key and a versionId results in S3Exception: The specified version does not exist.

I'm guessing that the version is considered a subresource of the key, but it seems strange that we get a message about the version not existing when the key doesn't exist either.

Expected Behavior

A NoSuchKeyException is thrown whenever the specified key does not exist, regardless whether a version is provided or not.

Current Behavior

  • Providing only a key and no versionId results in NoSuchKeyException: The specified key does not exist.
  • Providing both a key and a versionId results in S3Exception: The specified version does not exist.

Steps to Reproduce

  • Create a versioned bucket.
  • Invoke S3Client#getObject(GetObjectRequest) using an invalid key and any versionId.
  • Note exception returned is S3Exception instead of NoSuchKeyException.

Context

I would like accurately tell my consumer that the key is invalid. Telling them the version does not exist is "true" but missing the context that the key is actually missing.

Your Environment

  • AWS Java SDK version used: 2.15.63

  • JDK version used:

     openjdk version "1.8.0_242"
     OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
     OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.242-b08, mixed mode)
    
  • Operating System and version: OSX 10.15.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.service-apiThis issue is due to a problem in a service API, not the SDK implementation.service:s3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions