Closed zerg000000 closed 1 year ago
Have you actually seen this surface? I don't know that we have any code paths that can possibly get to that function with a ByteBuffer with no backing array.
@dchelimsky updated with example and detailed stacktrace.
aws-api supports either a byte array or an input stream for the AWS "blob" type, but not ByteBuffer. This is documented in https://github.com/cognitect-labs/aws-api/blob/main/doc/types.md. I'll add something to the README to make sure that doc is more visible.
FYI:
(def s3 (aws/client {:api :s3}))
(aws/validate-requests s3 true)
(aws/invoke s3 {:op :PutObject
:request {:Body (-> (RandomAccessFile. "deps.edn" "r")
(.getChannel)
(.map FileChannel$MapMode/READ_ONLY 0 10))
:Bucket "example-bucket"
:Key "sample.txt"}})
;; produces
{:clojure.spec.alpha/problems
({:path [:Body :byte-array],
:pred clojure.core/bytes?,
:val #object[java.nio.DirectByteBufferR 0x2662413f "java.nio.DirectByteBufferR[pos=0 lim=10 cap=10]"],
:via [:cognitect.aws.s3/PutObjectRequest :cognitect.aws.s3/Body],
:in [:Body]}
{:path [:Body :input-stream],
:pred (clojure.core/fn [%] (clojure.core/instance? java.io.InputStream %)),
:val #object[java.nio.DirectByteBufferR 0x2662413f "java.nio.DirectByteBufferR[pos=0 lim=10 cap=10]"],
:via [:cognitect.aws.s3/PutObjectRequest :cognitect.aws.s3/Body],
:in [:Body]}),
:clojure.spec.alpha/spec :cognitect.aws.s3/PutObjectRequest,
:clojure.spec.alpha/value
{:Body #object[java.nio.DirectByteBufferR 0x2662413f "java.nio.DirectByteBufferR[pos=0 lim=10 cap=10]"],
:Bucket "example-bucket",
:Key "sample.txt"},
:cognitect.anomalies/category :cognitect.anomalies/incorrect}
In Javadoc,
ByteBuffer.array
may returnUnsupportedOperationException
and Javadoc suggest to call.hasArray
first.https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html#array--
Dependencies
Description with failing test case
Stacktrace
https://github.com/cognitect-labs/aws-api/blob/1fb906ac0552051f7e6297279f24b738d087101b/src/cognitect/aws/util.clj#L87