mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-22 01:11:40 +00:00
Fix 'Resource leak: <variable> is never closed' warnings (#2023)
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: - [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 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
This commit is contained in:
@@ -100,6 +100,14 @@ public class VideoSimUtil {
|
||||
/**
|
||||
* Gets the 10x10 (grayscale) image of a specific 36h11 AprilTag.
|
||||
*
|
||||
* <p>WARNING: This creates a {@link RawFrame} instance but does not close it, which would result
|
||||
* in a resource leak if the {@link Mat} is garbage-collected. Unfortunately, closing the {@code
|
||||
* RawFrame} inside this function would delete the underlying data that backs the {@code
|
||||
* ByteBuffer} that is passed to the {@code Mat} constructor (see comments on <a
|
||||
* href="https://github.com/PhotonVision/photonvision/pull/2023">PR 2023</a> for details).
|
||||
* Luckily, this method is private and is (as of Aug 2025) only used to populate the {@link
|
||||
* #kTag36h11Images} static map at static-initialization time.
|
||||
*
|
||||
* @param id The fiducial id of the desired tag
|
||||
*/
|
||||
private static Mat get36h11TagImage(int id) {
|
||||
|
||||
@@ -122,6 +122,7 @@ public class VisionSystemSim {
|
||||
* @return If the camera was present and removed
|
||||
*/
|
||||
public boolean removeCamera(PhotonCameraSim cameraSim) {
|
||||
@SuppressWarnings("resource")
|
||||
boolean success = camSimMap.remove(cameraSim.getCamera().getName()) != null;
|
||||
camTrfMap.remove(cameraSim);
|
||||
return success;
|
||||
|
||||
Reference in New Issue
Block a user