Skip to content

Fix 'Resource leak: <variable> is never closed' warnings#2023

Merged
Gold856 merged 2 commits intoPhotonVision:mainfrom
kcooney:fix-auto-closeable-resource-leaks
Aug 19, 2025
Merged

Fix 'Resource leak: <variable> is never closed' warnings#2023
Gold856 merged 2 commits intoPhotonVision:mainfrom
kcooney:fix-auto-closeable-resource-leaks

Conversation

@kcooney
Copy link
Copy Markdown
Contributor

@kcooney kcooney commented Aug 2, 2025

Fix numerous places where using AutoCloseable objects without closing them.

Changes:

  • Upgrade JUnit from 5.10.0 to 5.11.4 (so @AutoClose can be used)
  • Use Files.copy() to copy files
  • Use try-with-resources when calling Files.list() or Files.walk()
  • Use try-with-resources or @AutoClose to close PhotonCamera and
    PhotonCameraSim objects created by tests
  • Update SQLConfigTest to use @TempDir

Meta

Merge checklist:

  • Pull Request title is short, imperative summary of proposed changes
  • The description documents the what and why
  • If this PR changes behavior or adds a feature, user documentation is updated
  • If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly
  • If this PR touches configuration, this is backwards compatible with settings back to v2024.3.1
  • If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated
  • If this PR addresses a bug, a regression test for it is added

@kcooney kcooney requested a review from a team as a code owner August 2, 2025 23:29
@kcooney kcooney marked this pull request as draft August 2, 2025 23:56
@kcooney kcooney force-pushed the fix-auto-closeable-resource-leaks branch 2 times, most recently from 123b881 to 68cf4e9 Compare August 3, 2025 00:57
@kcooney kcooney marked this pull request as ready for review August 3, 2025 01:49
@samfreund samfreund added bug Something isn't working backend Things relating to photon-core and photon-server labels Aug 4, 2025
@kcooney kcooney force-pushed the fix-auto-closeable-resource-leaks branch from 68cf4e9 to ac732d6 Compare August 7, 2025 17:20
@github-actions github-actions bot added the photonlib Things related to the PhotonVision library label Aug 7, 2025
Changes:
- Upgrade JUnit from 5.10.0 to 5.11.4 (so @autoclose can be used)
- Use Files.copy() to copy files
- Use try-with-resources when calling Files.list() or Files.walk()
- Use try-with-resources or @autoclose to close PhotonCamera and
  PhotonCameraSim objects created by tests
- Use try-with-resources when calling AprilTag.generate36h11AprilTagImage()
- Update SQLConfigTest to use @tempdir
@kcooney kcooney force-pushed the fix-auto-closeable-resource-leaks branch from ac732d6 to 2a40b18 Compare August 18, 2025 02:50
@kcooney
Copy link
Copy Markdown
Contributor Author

kcooney commented Aug 18, 2025

FYI: rebased the branch off of main

Gold856
Gold856 previously approved these changes Aug 19, 2025
@Gold856 Gold856 enabled auto-merge (squash) August 19, 2025 01:20
auto-merge was automatically disabled August 19, 2025 01:36

Head branch was pushed to by a user without write access

@kcooney kcooney force-pushed the fix-auto-closeable-resource-leaks branch from 49c4e12 to 7d622c2 Compare August 19, 2025 01:36
@Gold856 Gold856 merged commit 7d927ac into PhotonVision:main Aug 19, 2025
50 of 57 checks passed
Gold856 added a commit that referenced this pull request Oct 10, 2025
## Description

#2023 changed how file uploads were handled to use `Files.copy`, but
incorrectly didn't specify the `REPLACE_EXISTING` copy option, causing
file uploads to fail if the file already existed.

## Meta

Merge checklist:
- [x] Pull Request title is [short, imperative
summary](https://cbea.ms/git-commit/) of proposed changes
- [x] The description documents the _what_ and _why_
- [ ] If this PR changes behavior or adds a feature, user documentation
is updated
- [ ] If this PR touches photon-serde, all messages have been
regenerated and hashes have not changed unexpectedly
- [ ] If this PR touches configuration, this is backwards compatible
with settings back to v2025.3.2
- [ ] If this PR touches pipeline settings or anything related to data
exchange, the frontend typing is updated
- [ ] If this PR addresses a bug, a regression test for it is added
spacey-sooty pushed a commit to spacey-sooty/photonvision that referenced this pull request Dec 22, 2025
## Description

PhotonVision#2023 changed how file uploads were handled to use `Files.copy`, but
incorrectly didn't specify the `REPLACE_EXISTING` copy option, causing
file uploads to fail if the file already existed.

## Meta

Merge checklist:
- [x] Pull Request title is [short, imperative
summary](https://cbea.ms/git-commit/) of proposed changes
- [x] The description documents the _what_ and _why_
- [ ] If this PR changes behavior or adds a feature, user documentation
is updated
- [ ] If this PR touches photon-serde, all messages have been
regenerated and hashes have not changed unexpectedly
- [ ] If this PR touches configuration, this is backwards compatible
with settings back to v2025.3.2
- [ ] If this PR touches pipeline settings or anything related to data
exchange, the frontend typing is updated
- [ ] If this PR addresses a bug, a regression test for it is added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Things relating to photon-core and photon-server bug Something isn't working photonlib Things related to the PhotonVision library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants