org.apache.avro

## Class SystemLimitException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - java.lang.RuntimeException
      - - org.apache.avro.AvroRuntimeException
        - - org.apache.avro.SystemLimitException

All Implemented Interfaces:
  Serializable

    public class SystemLimitException
    extends AvroRuntimeException

Thrown to prevent making large allocations when reading potentially pathological input data from an untrusted source.

The following system properties can be set to limit the size of bytes, strings and collection types to be allocated:

- `org.apache.avro.limits.byte.maxLength`
limits the maximum size of `byte` types.

`org.apache.avro.limits.collectionItems.maxLength`
limits the maximum number of `map` and `list` items that can be read at once single sequence.
`org.apache.avro.limits.string.maxLength`
limits the maximum size of `string` types.

The default is to permit sizes up to `MAX_ARRAY_VM_LIMIT`.

See Also:
  Serialized Form

### Field Summary

Fields
`static String` `MAX_BYTES_LENGTH_PROPERTY`
`static String` `MAX_COLLECTION_LENGTH_PROPERTY`
`static String` `MAX_STRING_LENGTH_PROPERTY`

### Constructor Summary

Constructors
Constructor and Description
`SystemLimitException(String message)`

### Method Summary

All Methods Static Methods Concrete Methods
`static int` `checkMaxBytesLength(long length)` Check to ensure that reading the bytes is within the specified limits.
`static int` `checkMaxCollectionLength(long existing, long items)` Check to ensure that reading the specified number of items remains within the specified limits.
`static int` `checkMaxStringLength(long length)` Check to ensure that reading the string size is within the specified limits.

### Methods inherited from class java.lang.Throwable

`addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### MAX_BYTES_LENGTH_PROPERTY

    public static final String MAX_BYTES_LENGTH_PROPERTY

See Also:
  Constant Field Values

#### MAX_COLLECTION_LENGTH_PROPERTY

    public static final String MAX_COLLECTION_LENGTH_PROPERTY

See Also:
  Constant Field Values

#### MAX_STRING_LENGTH_PROPERTY

    public static final String MAX_STRING_LENGTH_PROPERTY

See Also:
  Constant Field Values

### Constructor Detail

#### SystemLimitException

    public SystemLimitException(String message)

### Method Detail

#### checkMaxBytesLength

    public static int checkMaxBytesLength(long length)

Check to ensure that reading the bytes is within the specified limits.

Parameters:
  `length` - The proposed size of the bytes to read
Returns:
  The size of the bytes if and only if it is within the limit and non-negative.
Throws:
  `UnsupportedOperationException` - if reading the datum would allocate a collection that the Java VM would be unable to handle
  `SystemLimitException` - if the decoding should fail because it would otherwise result in an allocation exceeding the set limit
  `AvroRuntimeException` - if the length is negative

#### checkMaxCollectionLength

    public static int checkMaxCollectionLength(long existing,
                                               long items)

Check to ensure that reading the specified number of items remains within the specified limits.

Parameters:
  `existing` - The number of elements items read in the collection
  `items` - The next number of items to read. In normal usage, this is always a positive, permitted value. Negative and zero values have a special meaning in Avro decoding.
Returns:
  The total number of items in the collection if and only if it is within the limit and non-negative.
Throws:
  `UnsupportedOperationException` - if reading the items would allocate a collection that the Java VM would be unable to handle
  `SystemLimitException` - if the decoding should fail because it would otherwise result in an allocation exceeding the set limit
  `AvroRuntimeException` - if the length is negative

#### checkMaxStringLength

    public static int checkMaxStringLength(long length)

Check to ensure that reading the string size is within the specified limits.

Parameters:
  `length` - The proposed size of the string to read
Returns:
  The size of the string if and only if it is within the limit and non-negative.
Throws:
  `UnsupportedOperationException` - if reading the items would allocate a collection that the Java VM would be unable to handle
  `SystemLimitException` - if the decoding should fail because it would otherwise result in an allocation exceeding the set limit
  `AvroRuntimeException` - if the length is negative