spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

GH-4705: Fix FilterExpressionTextParser to handle Long values in numeric literals

Open leehaut opened this issue 3 months ago • 3 comments

fixed: https://github.com/spring-projects/spring-ai/issues/4705 -- FilterExpressionTextParser treats all number literals as Integer, failing on Long values

leehaut avatar Oct 23 '25 14:10 leehaut

Hi @leehaut, thanks for your contribution.

I believe your PR has become irrelevant since we merged https://github.com/spring-projects/spring-ai/pull/3516.

Can you please confirm this is the case.

ericbottard avatar Oct 24 '25 09:10 ericbottard

Hi @ericbottard, I tried testing with long types or hexadecimal (0x) values, and found that ANTLR always converts them to int. ANTLR cannot distinguish between int and long. .e.g.

	@MethodSource("constantConstantProvider")
	@ParameterizedTest(name = "{index} => [{0}, expected={1}]")
	void testConstants(String expr, Object expectedValue) {
		Expression result = this.parser.parse(expr);
		assertThat(result).isEqualTo(new Expression(EQ, new Key("id"), new Value(expectedValue)));
	}

	static Stream<Arguments> constantConstantProvider() {
		return Stream.of(Arguments.of("id==" + Integer.MAX_VALUE, Integer.MAX_VALUE),
				Arguments.of("id==" + Integer.MIN_VALUE, Integer.MIN_VALUE),
				Arguments.of("id==" + Long.MAX_VALUE, Long.MAX_VALUE),
				Arguments.of("id==" + Long.MIN_VALUE, Long.MIN_VALUE), Arguments.of("id==" + 0x100, 0x100),
				Arguments.of("id==" + 1000000000000L, 1000000000000L), Arguments.of("id==" + Math.PI, Math.PI));
	}

leehaut avatar Oct 24 '25 09:10 leehaut

Hi,

the linked PR introduces support for longs by using the 1234L notation.

ericbottard avatar Oct 24 '25 10:10 ericbottard