Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NULL HttpEntity in headerFunction in HTTP inbound gateway #3114

Closed
andreiamariei opened this issue Nov 22, 2019 · 2 comments
Closed

NULL HttpEntity in headerFunction in HTTP inbound gateway #3114

andreiamariei opened this issue Nov 22, 2019 · 2 comments

Comments

@andreiamariei
Copy link

When trying to upgrade from version 5.1.8 to 5.2.1, our HTTP inbound gateway started throwing NPEs when evaluating header functions. Our code is quite basic:

IntegrationFlows.from(
                        inboundGateway( gatewayPath )
                                .headerFunction(SOME_HEADER, ent -> getSomeHeaderValue(ent ) )  // ent is null

Seems to be related to the call FunctionExpression.getValue(...) which ignores EvaluationContext.getRootObject()

Do you need more info on this?

@artembilan
Copy link
Member

Confirmed.
Looks like FunctionExpression has to be fixed:

	public Object getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
		return getValue(rootObject);
	}

The rootObject might be null, so we need to consult with the context for that one instead.

Would you mind to provide a fix?

Thanks

@artembilan
Copy link
Member

The regression has been done here: 8f86ef9#diff-9f816d4b97a4332fc0368b15f4fdbc8aR277.

Where it calls an Expression.getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> desiredResultType) with null for rootObject.
This is not what we should call according SpEL contract. So, the fix must be done in the ExpressionEvalMap.

Although FunctionExpression may be effected with some refactoring as well.

Looks like a bit involved - will fix soon...

@artembilan artembilan self-assigned this Nov 22, 2019
artembilan added a commit to artembilan/spring-integration that referenced this issue Nov 22, 2019
Fixes spring-projects#3114

The contract of SpEL with its
`getValue(EvaluationContext context, @nullable Object rootObject)` is
that we need to deal with provided `rootObject` even if it is `null`
and don't consult with `context.getRootObject()`

* Fix `ExpressionEvalMap` to have an internal `rootExplicitlySet`
to indicate that `root` explicitly provided by consumer, even if it is null.
According this flag call respective `Expression.getValue()`
* Add `@Nullable` to methods and their arguments into `ExpressionEvalMap`
& `FunctionExpression` to honor `Expression` contracts
* Populate an `HttpEntity` explicitly into `ExpressionEvalMap` from the
`HttpRequestHandlingEndpointSupport` and `WebFluxInboundEndpoint` for
full picture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants