Skip to content

AbstractObjectParser methods should throw IAE for invalid values #130797

Open
@joshua-adams-1

Description

@joshua-adams-1

Currently, the following AbstractObjectParser methods:

  • declareInt
  • declareIntOrNull
  • declareLong
  • declareLongOrNull
  • declareIntArray
  • declareLongArray

truncate any floats / doubles passed to them, rather than throwing an IllegalArgumentException. This means that fields defined as integer / long, can actually accept floats and doubles.

There are two issues with this:

  1. The customer may be dependent on this invalid behaviour (this is an integer defined field, and so should only accept integers) and behaviour from our side cannot be guaranteed. Therefore, imposing stricter validation ensures consistent behaviour moving forward/
  2. The following methods are used to parse API request bodies. When APIs accept parameters via query parameters, tighter validation is present, and floats are not accepted. This leads to a discrepancy between APIs accepting parameters via the request body and rejecting them as query parameters.

The scope of this change is to modify the above methods - any other others missing from the list - to throw an IllegalArgumentException when non-integer / non-long values are passed. This will ensure consistency between parameters passed in the body of the request, and those in the query parameters

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions