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

use try with resources in JsonUtil #9879

Merged
merged 2 commits into from
Sep 11, 2023
Merged

use try with resources in JsonUtil #9879

merged 2 commits into from
Sep 11, 2023

Conversation

pdurbin
Copy link
Member

@pdurbin pdurbin commented Sep 5, 2023

What this PR does / why we need it:

According to Sonarcloud:

"Failure to properly close resources will result in a resource leak which could bring first the application and then perhaps the box the application is on to their knees."

Which issue(s) this PR closes:

Special notes for your reviewer:

You can see the bug at

https://sonarcloud.io/code?id=IQSS_dataverse&selected=IQSS_dataverse%3Asrc%2Fmain%2Fjava%2Fedu%2Fharvard%2Fiq%2Fdataverse%2Futil%2Fjson%2FJsonUtil.java

Screen Shot 2023-09-05 at 4 20 31 PM

Screen Shot 2023-09-05 at 4 20 46 PM

Unfortunately, Netbeans didn't flag this error for me locally and therefore didn't offer any kind of automatic fix. Netbeans does seem to have the right rule enabled:

Screen Shot 2023-09-05 at 3 02 31 PM

I ended up following https://guides.dataverse.org/en/5.14/developers/tools.html#sonarqube more or less to set up SonarQube and used the following script to test just the one file I was editing:

#!/bin/sh
mvn clean verify sonar:sonar \
  -Dsonar.projectKey=dataverse \
  -Dsonar.projectName='dataverse' \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.sources='src/main/java/edu/harvard/iq/dataverse/util/json/JsonUtil.java' \
  -Dsonar.token=sqp_4a726f4a698d074c795c7c407e100bfa1e81847f

Suggestions on how to test this:

This change is covered by unit tests, so I don't think manual testing is required. However, loading an external tool should test it.

Does this PR introduce a user interface change? If mockups are available, please link/include them here:

No.

Is there a release notes update needed for this change?:

No.

Additional documentation:

None. However, we now have an issue about Sonar:

@github-actions

This comment has been minimized.

@pdurbin
Copy link
Member Author

pdurbin commented Sep 6, 2023

I just tried IntelliJ Community 2023.2.1

It was easy to install SonarLint. As shown in the screenshot below this particular "not using try with resources" bug was flagged. In addition, you can right click and analyze just the one file. No auto-fix is offered.

Screen Shot 2023-09-06 at 11 41 02 AM

@rtreacy rtreacy self-assigned this Sep 11, 2023
Copy link
Contributor

@rtreacy rtreacy left a comment

Choose a reason for hiding this comment

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

looks good

@rtreacy rtreacy removed their assignment Sep 11, 2023
@coveralls
Copy link

Coverage Status

coverage: 19.971% (+0.002%) from 19.969% when pulling 069bb91 on 9315-jsontry into 62a9811 on develop.

@github-actions
Copy link

📦 Pushed preview images as

ghcr.io/gdcc/dataverse:9315-jsontry
ghcr.io/gdcc/configbaker:9315-jsontry

🚢 See on GHCR. Use by referencing with full name as printed above, mind the registry name.

@kcondon kcondon merged commit 2c6afef into develop Sep 11, 2023
14 of 15 checks passed
@kcondon kcondon deleted the 9315-jsontry branch September 11, 2023 21:30
@pdurbin pdurbin added this to the 6.1 milestone Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants