Skip to content

Conversation

artembilan
Copy link
Member

When no cause and no clean context of the exception thrown, the code place where an exception has been created is confusing.

  • Fix SimpleMessageStore to create an out of capacity exception in the addMessagesToGroup() exactly at the point where it is thrown
  • Fix FunctionExpression and SupplierExpression do not pre-create readOnlyException: it is unlikely these kind of expressions are going to be used in the SpEL write context, so we save some time and memory not creating extra object and the plain call throw new gives us a clean context what method call has ended up with such an exception

Comment on lines 284 to 286
throw new MessagingException(getClass().getSimpleName() +
" was out of capacity (" + this.groupCapacity + ") for group '" + groupId +
"', try constructing it with a larger number.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be extracted to a method to avoid the duplicate code.

When no `cause` and no clean context of the exception thrown,
the code place where an exception has been created is confusing.

* Fix `SimpleMessageStore` to create an `out of capacity` exception in the
`addMessagesToGroup()` exactly at the point where it is thrown
* Fix `FunctionExpression` and `SupplierExpression` do not pre-create `readOnlyException`:
it is unlikely these kind of expressions are going to be used in the SpEL `write` context,
so we save some time and memory not creating extra object and the plain call `throw new`
gives us a clean context what method call has ended up with such an exception
…eStore`

to avoid duplication.
Even if we got in the end extra line in th stack trace, it is still clear from
where it is thrown:

```
org.springframework.messaging.MessagingException: SimpleMessageStore was out of capacity (1) for group 'foo', try constructing it with a larger number.

	at org.springframework.integration.store.SimpleMessageStore.outOfCapacityException(SimpleMessageStore.java:324)
	at org.springframework.integration.store.SimpleMessageStore.addMessagesToGroup(SimpleMessageStore.java:302)
	at org.springframework.integration.store.AbstractMessageGroupStore.addMessageToGroup(AbstractMessageGroupStore.java:189)
	at org.springframework.integration.store.SimpleMessageStoreTests.shouldNotHoldMoreThanGroupCapacity(SimpleMessageStoreTests.java:128)
```
@artembilan artembilan force-pushed the dont_do_pre-build_exceptions branch from 0a78eaf to a7616f0 Compare January 5, 2023 16:22
@artembilan artembilan requested a review from garyrussell January 5, 2023 16:22
@garyrussell garyrussell merged commit 308f3fa into spring-projects:main Jan 5, 2023
@artembilan artembilan deleted the dont_do_pre-build_exceptions branch January 6, 2023 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants