Skip to content

NamedParameterUtils has broken square brackets handling #27925

Closed

Description

@artembilan

This is a simple unit test which passes with the 5.3.x but fails with the current 6.0 milestones:

	@Test
	void namedParamMapReference() {
		String insert = "insert into foos (id) values (:headers[id])";
		class Foo {

			final Map<String, Object> headers = new HashMap<>();

			public Foo() {
				this.headers.put("id", UUID.randomUUID());
			}

			public Map<String, Object> getHeaders() {
				return this.headers;
			}

		}

		Foo foo = new Foo();

		Object[] params =
				NamedParameterUtils.buildValueArray(NamedParameterUtils.parseSqlStatement(insert),
						new BeanPropertySqlParameterSource(foo), null);

		assertThat(params[0]).isEqualTo(foo.getHeaders().get("id"));
	}

The point is that we may have a reference for the value from nested Map property.

The typical use case is messaging, for example with Spring Integration, where a Message<?> in the request is used as a source for parameter values.

We even advertise this in the docs: https://docs.spring.io/spring-integration/docs/current/reference/html/jdbc.html#jdbc-outbound-channel-adapter.

I suspect that the cause for breaking change is this fix: 64b6bee. Or the previous one: 86eda27.

Thanks

Activity

  1. added
    status: waiting-for-triage
    on Jan 12, 2022
  2. added
    in: data
    type: regression
    on Jan 12, 2022
  3. added this to the Triage Queue milestone on Jan 12, 2022
  4. quaff commented on Jan 17, 2022

    @quaff
    Contributor

    parameterName is changed from headers[id] to headers after commit 64b6bee

  5. removed
    status: waiting-for-triage
    on Jan 18, 2022
  6. self-assigned this
    on Mar 16, 2022
  7. modified the milestones: 6.0.0-M3, 6.0.0-M4 on Mar 16, 2022
  8. modified the milestones: 6.0.0-M4, 6.0.0-M5 on May 4, 2022
  9. modified the milestones: 6.0.0-M5, 6.0.0-M6 on Jul 8, 2022
  10. modified the milestones: 6.0.0-M6, 6.0.0-RC1 on Sep 12, 2022
  11. rstoyanchev commented on Oct 11, 2022

    @rstoyanchev
    Contributor

    Maybe consider #17773 as well for potential improvement to the parsing algorithm.

  12. modified the milestones: 6.0.0-RC1, 6.0.0-RC2 on Oct 11, 2022
  13. jhoeller commented on Oct 18, 2022

    @jhoeller
    Contributor

    With some custom treatment, we can restore the original intent of #27716 as well as preserve square brackets for index/key expressions. Finally making it into RC2...

  14. added a commit that references this issue on Sep 17, 2026
    d4fac82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions