use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class UserType method validate.
// Note: the only reason we override this is to provide nicer error message, but since that's not that much code...
@Override
public void validate(ByteBuffer bytes) throws MarshalException {
ByteBuffer input = bytes.duplicate();
for (int i = 0; i < size(); i++) {
// we allow the input to have less fields than declared so as to support field addition.
if (!input.hasRemaining())
return;
if (input.remaining() < 4)
throw new MarshalException(String.format("Not enough bytes to read size of %dth field %s", i, fieldNameAsString(i)));
int size = input.getInt();
// size < 0 means null value
if (size < 0)
continue;
if (input.remaining() < size)
throw new MarshalException(String.format("Not enough bytes to read %dth field %s", i, fieldNameAsString(i)));
ByteBuffer field = ByteBufferUtil.readBytes(input, size);
types.get(i).validate(field);
}
// We're allowed to get less fields than declared, but not more
if (input.hasRemaining())
throw new MarshalException("Invalid remaining data after end of UDT value");
}
use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class DynamicCompositeType method validateComparator.
protected AbstractType<?> validateComparator(int i, ByteBuffer bb) throws MarshalException {
AbstractType<?> comparator = null;
if (bb.remaining() < 2)
throw new MarshalException("Not enough bytes to header of the comparator part of component " + i);
int header = ByteBufferUtil.readShortLength(bb);
if ((header & 0x8000) == 0) {
if (bb.remaining() < header)
throw new MarshalException("Not enough bytes to read comparator name of component " + i);
ByteBuffer value = ByteBufferUtil.readBytes(bb, header);
String valueStr = null;
try {
valueStr = ByteBufferUtil.string(value);
comparator = TypeParser.parse(valueStr);
} catch (CharacterCodingException ce) {
// ByteBufferUtil.string failed.
// Log it here and we'll further throw an exception below since comparator == null
logger.error("Failed with [{}] when decoding the byte buffer in ByteBufferUtil.string()", ce.toString());
} catch (Exception e) {
// parse failed.
// Log it here and we'll further throw an exception below since comparator == null
logger.error("Failed to parse value string \"{}\" with exception: [{}]", valueStr, e.toString());
}
} else {
comparator = aliases.get((byte) (header & 0xFF));
}
if (comparator == null)
throw new MarshalException("Cannot find comparator for component " + i);
else
return comparator;
}
use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class Attributes method getTimeToLive.
public int getTimeToLive(QueryOptions options, int defaultTimeToLive) throws InvalidRequestException {
if (timeToLive == null)
return defaultTimeToLive;
ByteBuffer tval = timeToLive.bindAndGet(options);
if (tval == null)
return 0;
if (tval == ByteBufferUtil.UNSET_BYTE_BUFFER)
return defaultTimeToLive;
try {
Int32Type.instance.validate(tval);
} catch (MarshalException e) {
throw new InvalidRequestException("Invalid timestamp value: " + tval);
}
int ttl = Int32Type.instance.compose(tval);
if (ttl < 0)
throw new InvalidRequestException("A TTL must be greater or equal to 0, but was " + ttl);
if (ttl > MAX_TTL)
throw new InvalidRequestException(String.format("ttl is too large. requested (%d) maximum (%d)", ttl, MAX_TTL));
if (defaultTimeToLive != LivenessInfo.NO_TTL && ttl == LivenessInfo.NO_TTL)
return LivenessInfo.NO_TTL;
return ttl;
}
use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class AbstractRow method validateData.
public void validateData(TableMetadata metadata) {
validateClustering(metadata, clustering());
primaryKeyLivenessInfo().validate();
if (deletion().time().localDeletionTime() < 0)
throw new MarshalException("A local deletion time should not be negative in '" + metadata + "'");
apply(cd -> cd.validate());
}
use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class SetType method fromJSONObject.
@Override
public Term fromJSONObject(Object parsed) throws MarshalException {
if (parsed instanceof String)
parsed = Json.decodeJson((String) parsed);
if (!(parsed instanceof List))
throw new MarshalException(String.format("Expected a list (representing a set), but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
List list = (List) parsed;
Set<Term> terms = new HashSet<>(list.size());
for (Object element : list) {
if (element == null)
throw new MarshalException("Invalid null element in set");
terms.add(elements.fromJSONObject(element));
}
return new Sets.DelayedValue(elements, terms);
}
Aggregations