kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 0746b46f6487a81dc83c607e67dc31281780e78d6e7e8895eb1b39d0a1e25fa4 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-12-10 12:12 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-02-23 17:41 +01:00 |
| Parents | 4bb946c55b59 |
4 files changed
modified changelog/README.md +1 −0
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | - [improvement] JAVA-1030: Log token to replica map computation times. |
| 12 | 12 | - [bug] JAVA-1039: Minor bugs in Event Debouncer. |
| 13 | 13 | - [improvement] JAVA-843: Disable frozen checks in mapper. |
| 14 | +- [improvement] JAVA-833: Improve message when a nested type can't be serialized. | |
| 14 | 15 | |
| 15 | 16 | Merged from 2.0 branch: |
| 16 | 17 |
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +3 −4
| @@ -713,12 +713,11 @@ | ||
| 713 | 713 | if (value == null) |
| 714 | 714 | return null; |
| 715 | 715 | |
| 716 | - DataType dt = TypeCodec.getDataTypeFor(value); | |
| 717 | - if (dt == null) | |
| 718 | - throw new IllegalArgumentException(String.format("Value of type %s does not correspond to any CQL3 type", value.getClass())); | |
| 719 | - | |
| 720 | 716 | try { |
| 717 | + DataType dt = TypeCodec.getDataTypeFor(value); | |
| 721 | 718 | return dt.serialize(value, protocolVersion); |
| 719 | + } catch (IllegalArgumentException e) { | |
| 720 | + throw new IllegalArgumentException(String.format("Could not serialize value of type %s", value.getClass()), e); | |
| 722 | 721 | } catch (InvalidTypeException e) { |
| 723 | 722 | // In theory we couldn't get that if getDataTypeFor does his job correctly, |
| 724 | 723 | // but there is no point in sending an exception that the user won't expect if we're |
modified driver-core/src/main/java/com/datastax/driver/core/SimpleStatement.java +1 −1
| @@ -96,7 +96,7 @@ | ||
| 96 | 96 | serializedValues[i] = DataType.serializeValue(value, protocolVersion); |
| 97 | 97 | } catch (IllegalArgumentException e) { |
| 98 | 98 | // Catch and rethrow to provide a more helpful error message (one that include which value is bad) |
| 99 | - throw new IllegalArgumentException(String.format("Value %d of type %s does not correspond to any CQL3 type", i, value.getClass())); | |
| 99 | + throw new IllegalArgumentException(String.format("Could not serialize value %d of type %s", i, value.getClass()), e.getCause()); | |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | return serializedValues; |
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +8 −10
| @@ -159,7 +159,7 @@ | ||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /* This is ugly, but not sure how we can do much better/faster |
| 162 | - * Returns null if it's doesn't correspond to a known type. | |
| 162 | + * Throws IllegalArgumentException if it's doesn't correspond to a known type. | |
| 163 | 163 | * |
| 164 | 164 | * Also, note that this only a dataType that is fit for the value, |
| 165 | 165 | * but for instance, for a UUID, this will return DataType.uuid() but |
| @@ -187,7 +187,7 @@ | ||
| 187 | 187 | return DataType.decimal(); |
| 188 | 188 | if (value instanceof BigInteger) |
| 189 | 189 | return DataType.varint(); |
| 190 | - return null; | |
| 190 | + throw new IllegalArgumentException("Type " + value.getClass().getName() + " does not correspond to any CQL type"); | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | if (value instanceof String) |
| @@ -210,7 +210,7 @@ | ||
| 210 | 210 | if (l.isEmpty()) |
| 211 | 211 | return DataType.list(DataType.blob()); |
| 212 | 212 | DataType eltType = getDataTypeFor(l.get(0)); |
| 213 | - return eltType == null ? null : DataType.list(eltType); | |
| 213 | + return DataType.list(eltType); | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | if (value instanceof Set) { |
| @@ -218,7 +218,7 @@ | ||
| 218 | 218 | if (s.isEmpty()) |
| 219 | 219 | return DataType.set(DataType.blob()); |
| 220 | 220 | DataType eltType = getDataTypeFor(s.iterator().next()); |
| 221 | - return eltType == null ? null : DataType.set(eltType); | |
| 221 | + return DataType.set(eltType); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | if (value instanceof Map) { |
| @@ -226,11 +226,9 @@ | ||
| 226 | 226 | if (m.isEmpty()) |
| 227 | 227 | return DataType.map(DataType.blob(), DataType.blob()); |
| 228 | 228 | Map.Entry<?, ?> e = m.entrySet().iterator().next(); |
| 229 | - DataType keyType = getDataTypeFor(e.getKey()); | |
| 230 | - DataType valueType = getDataTypeFor(e.getValue()); | |
| 231 | - return keyType == null || valueType == null | |
| 232 | - ? null | |
| 233 | - : DataType.map(keyType, valueType); | |
| 229 | + return DataType.map( | |
| 230 | + getDataTypeFor(e.getKey()), | |
| 231 | + getDataTypeFor(e.getValue())); | |
| 234 | 232 | } |
| 235 | 233 | |
| 236 | 234 | if (value instanceof UDTValue) { |
| @@ -241,7 +239,7 @@ | ||
| 241 | 239 | return ((TupleValue) value).getType(); |
| 242 | 240 | } |
| 243 | 241 | |
| 244 | - return null; | |
| 242 | + throw new IllegalArgumentException("Type " + value.getClass().getName() + " does not correspond to any CQL type"); | |
| 245 | 243 | } |
| 246 | 244 | |
| 247 | 245 | private static ByteBuffer pack(List<ByteBuffer> buffers, int elements, ProtocolVersion version) { |