Details
-
Type:
Defect
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: Release 1.3
-
Fix Version/s: Release 1.6
-
Component/s: None
-
Labels:None
-
Patch:Code and Test
-
Approval:Incomplete
Description
Current patch: byte-short-array-ctors.diff
The behavior of byte-array and short-array is inconsistent with the other <type>-array functions and with the into-array function when invoked with types other than byte or short. All of the other cases upcast to Number, then extract the primitive value, allowing this operation to succeed (assuming the value is in range). byte-array and short-array throw a ClassCastException.
Example:
base64v3a=> (into-array Byte/TYPE [1 2 3 4]) ;; int to byte ok #<byte[] [B@5ee04fd> base64v3a=> (byte-array [1 2 3 4]) ;; int to byte NOT ok!! ClassCastException java.lang.Long cannot be cast to java.lang.Byte clojure.lang.Numbers.byte_array (Numbers.java:1418) base64v3a=> (long-array [1 2 3 4]) ;; int to long ok #<long[] [J@3f9f4d1d>
into-array (via RT.seqToTypedArray) and the other <type>-array functions all upcast to Number (via Numbers.<type>_array}}), then obtain the proper primitive value. Numbers.byte-array and Numbers.short-array do casts directly to Byte and Short (yielding the ClassCastException).
The attached patch makes the Byte and Short cases match the other types and the into-array behavior. Tests are included. The submitter is a contributor.
Attachments
Activity
| Field | Original Value | New Value |
|---|---|---|
| Attachment | clj766.patch [ 10174 ] |
| Attachment | clj766.patch [ 10174 ] |
| Attachment | byte-short-array-ctors.diff [ 11887 ] |
| Attachment | byte-short-array-ctors.diff [ 11887 ] |
| Attachment | byte-short-array-ctors.diff [ 11890 ] |
| Approval | Triaged [ 10120 ] |
| Approval | Triaged [ 10120 ] | Vetted [ 10003 ] |
| Fix Version/s | Release 1.6 [ 10157 ] |
| Patch | Code and Test [ 10002 ] |
| Assignee | Alex Miller [ alexmiller ] |
| Description |
Example:
{noformat} base64v3a=> (into-array Byte/TYPE [1 2 3 4]) #<byte[] [B@5ee04fd> base64v3a=> (byte-array [1 2 3 4]) ClassCastException java.lang.Long cannot be cast to java.lang.Byte clojure.lang.Numbers.byte_array (Numbers.java:1418) {noformat} While into-array (via RT.seqToTypedArray) casts each element prior to inserting into the array, byte-array (via Numbers.byte_array) does an unchecked cast to Byte. |
Current patch: byte-short-array-ctors.diff
The behavior of {{byte-array}} and {{short-array}} is inconsistent with the other {{<type>-array}} functions and with the {{into-array}} function when invoked with types other than byte or short. All of the other cases upcast to Number, then extract the primitive value, allowing this operation to succeed (assuming the value is in range). {{byte-array}} and {{short-array}} throw a ClassCastException. Example: {noformat} base64v3a=> (into-array Byte/TYPE [1 2 3 4]) ;; int to byte ok #<byte[] [B@5ee04fd> base64v3a=> (byte-array [1 2 3 4]) ;; int to byte NOT ok!! ClassCastException java.lang.Long cannot be cast to java.lang.Byte clojure.lang.Numbers.byte_array (Numbers.java:1418) base64v3a=> (long-array [1 2 3 4]) ;; long to int ok #<long[] [J@3f9f4d1d> {noformat} {{into-array}} (via {{RT.seqToTypedArray}}) and the other {{<type>-array}} functions all upcast to Number (via Numbers.<type>_array}}), then obtain the proper primitive value. {{Numbers.byte-array}} and {{Numbers.short-array}} do casts directly to Byte and Short (yielding the ClassCastException). The attached patch makes the Byte and Short cases match the other types and the {{into-array}} behavior. Tests are included. The submitter is a contributor. |
| Approval | Vetted [ 10003 ] | Incomplete [ 10006 ] |
| Assignee | Alex Miller [ alexmiller ] | Karsten Schmidt [ toxi ] |
| Description |
Current patch: byte-short-array-ctors.diff
The behavior of {{byte-array}} and {{short-array}} is inconsistent with the other {{<type>-array}} functions and with the {{into-array}} function when invoked with types other than byte or short. All of the other cases upcast to Number, then extract the primitive value, allowing this operation to succeed (assuming the value is in range). {{byte-array}} and {{short-array}} throw a ClassCastException. Example: {noformat} base64v3a=> (into-array Byte/TYPE [1 2 3 4]) ;; int to byte ok #<byte[] [B@5ee04fd> base64v3a=> (byte-array [1 2 3 4]) ;; int to byte NOT ok!! ClassCastException java.lang.Long cannot be cast to java.lang.Byte clojure.lang.Numbers.byte_array (Numbers.java:1418) base64v3a=> (long-array [1 2 3 4]) ;; long to int ok #<long[] [J@3f9f4d1d> {noformat} {{into-array}} (via {{RT.seqToTypedArray}}) and the other {{<type>-array}} functions all upcast to Number (via Numbers.<type>_array}}), then obtain the proper primitive value. {{Numbers.byte-array}} and {{Numbers.short-array}} do casts directly to Byte and Short (yielding the ClassCastException). The attached patch makes the Byte and Short cases match the other types and the {{into-array}} behavior. Tests are included. The submitter is a contributor. |
Current patch: byte-short-array-ctors.diff
The behavior of {{byte-array}} and {{short-array}} is inconsistent with the other {{<type>-array}} functions and with the {{into-array}} function when invoked with types other than byte or short. All of the other cases upcast to Number, then extract the primitive value, allowing this operation to succeed (assuming the value is in range). {{byte-array}} and {{short-array}} throw a ClassCastException. Example: {noformat} base64v3a=> (into-array Byte/TYPE [1 2 3 4]) ;; int to byte ok #<byte[] [B@5ee04fd> base64v3a=> (byte-array [1 2 3 4]) ;; int to byte NOT ok!! ClassCastException java.lang.Long cannot be cast to java.lang.Byte clojure.lang.Numbers.byte_array (Numbers.java:1418) base64v3a=> (long-array [1 2 3 4]) ;; int to long ok #<long[] [J@3f9f4d1d> {noformat} {{into-array}} (via {{RT.seqToTypedArray}}) and the other {{<type>-array}} functions all upcast to Number (via Numbers.<type>_array}}), then obtain the proper primitive value. {{Numbers.byte-array}} and {{Numbers.short-array}} do casts directly to Byte and Short (yielding the ClassCastException). The attached patch makes the Byte and Short cases match the other types and the {{into-array}} behavior. Tests are included. The submitter is a contributor. |
See
CLJ-678.CLJ-678.