Skip to content

SLING-12394 improve ResourceResolver handling#39

Open
joerghoh wants to merge 1 commit intomasterfrom
SLING-12394
Open

SLING-12394 improve ResourceResolver handling#39
joerghoh wants to merge 1 commit intomasterfrom
SLING-12394

Conversation

@joerghoh
Copy link
Contributor

  • Open all ResourceResolvers in a try-with-resource-based approach, which make the code easier to read
  • remove redundant nullchecks

*/
public ResourceResolver createResourceResolver() {
ResourceResolver resolver = null;
public @NotNull ResourceResolver createResourceResolver() {
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC this change will result in exceptions rather than silent swallows if the factory is null. That might its own consequences. What is the reasoning behind this change?

Copy link

Choose a reason for hiding this comment

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

I agree with @stefan-egli's concern. There are quite a few places where we had a null check before.

@joerghoh I suggest to throw a NullPointerException (or something more specific) instead of a RuntimeException and to catch and log this exception in the places where we used to have a null check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These null-checks seem to be added rather by accident than really planned. Otherwise all places where no null-checks exist would need to be augmented with these checks as well, and that was not a problem for a very long time.

Silently swallowing these exceptions (and therefor not executing the expected action) is also not a good pattern. On the other hand side the LoginException happens mostly due to configuration issues (also rare, because createResourceResolver code is not exported, and thus will only be used by the Sling event code), and therefor they should be easily fixable. So in the end the actual type of issue does not seem to be a problem, which is likely to happen frequently.
And for that reason I think it's possible to adjust the way errors are handled, as this is contained in this code. We might want to add a Thread.UncaughtExceptionHandler to the threads of the job threadpool(s).

*/
public ResourceResolver createResourceResolver() {
ResourceResolver resolver = null;
public @NotNull ResourceResolver createResourceResolver() {
Copy link

Choose a reason for hiding this comment

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

I agree with @stefan-egli's concern. There are quite a few places where we had a null check before.

@joerghoh I suggest to throw a NullPointerException (or something more specific) instead of a RuntimeException and to catch and log this exception in the places where we used to have a null check.

Comment on lines -144 to -145
final ResourceResolver resolver = configuration.createResourceResolver();
if ( resolver != null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

Comment on lines -334 to -335
ResourceResolver resolver = configuration.createResourceResolver();
if ( resolver != null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

Comment on lines -390 to -391
final ResourceResolver resolver = configuration.createResourceResolver();
if ( resolver != null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

Comment on lines -75 to -76
final ResourceResolver resolver = this.configuration.createResourceResolver();
if ( resolver != null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

Comment on lines -200 to -201
final ResourceResolver resolver = this.configuration.createResourceResolver();
if ( resolver != null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

Comment on lines -396 to -397
final ResourceResolver resolver = this.configuration.createResourceResolver();
if ( resolver == null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

Comment on lines -64 to -65
final ResourceResolver resolver = configuration.createResourceResolver();
if ( resolver == null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

Comment on lines -85 to -86
final ResourceResolver resolver = configuration.createResourceResolver();
if ( resolver != null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

Comment on lines -158 to -159
final ResourceResolver resolver = configuration.createResourceResolver();
if ( resolver != null ) {
Copy link

Choose a reason for hiding this comment

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

Here we have a null check. Should we handle the exception here instead?

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 4, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
60.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

2 similar comments
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
60.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
60.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants