Skip to content

SLING-11458 - fixed a regresssion for the original Ticket SLING-9626#29

Open
schaefa wants to merge 4 commits into
masterfrom
issue/SLING-11458
Open

SLING-11458 - fixed a regresssion for the original Ticket SLING-9626#29
schaefa wants to merge 4 commits into
masterfrom
issue/SLING-11458

Conversation

@schaefa

@schaefa schaefa commented Jul 15, 2022

Copy link
Copy Markdown
Contributor

The Json Writer that wraps the response writer must not be flushed or closed as this can lead to issues down the chain

The Json Writer that wraps the response writer must not be flushed or closed as this can lead to issues down the chain
@kwin

kwin commented Jul 16, 2022

Copy link
Copy Markdown
Member

I would suggest using https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/output/CloseShieldWriter.html#wrap-java.io.Writer- instead. Then you can continue using try with resources because not calling close on JSONWriter is dangerous as it might perform other operations than just closing the underlying writer.

@schaefa

schaefa commented Jul 18, 2022

Copy link
Copy Markdown
Contributor Author

@kwin First this does not work as it replaces the writer when closed is called but I also think that we should make it explicit there as this is important. Also SonarCloud is wrong here - I think.

@kwin

kwin commented Jul 18, 2022

Copy link
Copy Markdown
Member

First this does not work as it replaces the writer when closed is called

I am not following here. You can just use try (JsonWriter writer = Json.createWriter(CloseShieldWriter.wrap(response.getWriter()))) in

try (JsonWriter writer = Json.createWriter(response.getWriter())) {
.

but I also think that we should make it explicit there as this is important.

I think using CloseShieldWriter is way more explicit than just not closing.

Also SonarCloud is wrong here - I think.

In this particular case maybe yes, but as stated above, it may be possible that in the future another implementation of JSONWriter may do necessary cleanup in its close() apart from just delegating to its underlying writer.

@schaefa

schaefa commented Jul 18, 2022

Copy link
Copy Markdown
Contributor Author

@kwin The Close Shield Writer is not just preventing the close but it is replacing the writer:

public void close() {
    this.out = ClosedWriter.CLOSED_WRITER;
}

This will lead to failures in the IT tests of this module but I am pretty sure this will lead to issues when using it.

@kwin

kwin commented Jul 18, 2022

Copy link
Copy Markdown
Member

close() is the last method called on an instance of try with resources so I fail to see how this would have a negative impact. The CloseShieldWriter uses that to detect in case close is called twice, but it won’t have an effect on either the wrapped reader nor on any wrappers of CloseShieldWriter.

@schaefa

schaefa commented Jul 18, 2022

Copy link
Copy Markdown
Contributor Author

@kwin You give it a try (on both execute() methods):
try (JsonWriter writer = Json.createWriter(CloseShieldWriter.wrap(response.getWriter()))) {

This will yield 4 IT test failure:

[ERROR] Errors:
[ERROR] GraphQLServletIT.testGqlExt:112->GraphQLCoreTestSupport.getContent:198->GraphQLCoreTestSupport.executeRequest:188 » IO
[ERROR] GraphQLServletIT.testMultipleSchemaProviders:245->GraphQLCoreTestSupport.getContent:198->GraphQLCoreTestSupport.executeRequest:188 » IO
[ERROR] GraphQLServletIT.testOtherExtAndOtherSelector:222->GraphQLCoreTestSupport.getContent:198->GraphQLCoreTestSupport.executeRequest:188 » IO
[ERROR] GraphQLServletIT.testOtherExtAndTestingSelector:216->GraphQLCoreTestSupport.getContent:198->GraphQLCoreTestSupport.executeRequest:188 » IO

No failure with my solution

@schaefa

schaefa commented Jul 21, 2022

Copy link
Copy Markdown
Contributor Author

Updated the code to use a Wrapper to prevent the closure to satisfy the SonarCloud code check

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@raducotescu

raducotescu commented Jul 25, 2022

Copy link
Copy Markdown
Member

This issue should be fixed in Sling in a more generic way and not only in this module - see https://lists.apache.org/thread/lytsl0b23d56xkmvsvnoxm4d7skxcq5h for more details.

@sonarqubecloud

sonarqubecloud Bot commented Apr 5, 2023

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

2 similar comments
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@sonarqubecloud

sonarqubecloud Bot commented Jan 8, 2024

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@sonarqubecloud

sonarqubecloud Bot commented Feb 8, 2024

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

3 similar comments
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

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