This patch suppresses 29 "Resource leak, "checkpoint" is never closed" warnings.
Here is what they mean, and why they can be ignored:
All 29 cases of this warning follow this pattern:
Checkpoint is a class coming from SpecialOutfit.java, that implements the interface AutoCloseable.
AutoCloseable is used to defined an object that holds resources, just like Closeable. Compilers will throw a warning if they notice that instances of such class fail to call their close() method one way or another.
Here are the resource-related methods of Checkpoint:
Compilers are unable to understand that the scenario inside Checkpoint.restore(), in which Checkpoint.close() isn't called, simply happens because its result was already achieved. Hence, the warning will be thrown, without being an actual problem.
Edit: spelling
Here is what they mean, and why they can be ignored:
All 29 cases of this warning follow this pattern:
Java:
Checkpoint checkpoint = new Checkpoint();
try
{
// do something
}
finally
{
checkpoint.restore();
}
Checkpoint is a class coming from SpecialOutfit.java, that implements the interface AutoCloseable.
AutoCloseable is used to defined an object that holds resources, just like Closeable. Compilers will throw a warning if they notice that instances of such class fail to call their close() method one way or another.
Here are the resource-related methods of Checkpoint:
Java:
public class SpecialOutfit
{
private static final Set<Checkpoint> allCheckpoints = new HashSet<Checkpoint>();
public static class Checkpoint
implements AutoCloseable
{
public Checkpoint()
{
// <saves your current equipment>
synchronized ( SpecialOutfit.class )
{
SpecialOutfit.allCheckpoints.add( this);
}
}
public void restore()
{
// If this checkpoint has been closed, don't restore using it
if ( !this.known() )
{
return;
}
// <re-equips the content of the Checkpoint>
this.close();
}
public void close()
{
// For use with "try with resource", once we upgrade to a better Java version
synchronized ( SpecialOutfit.class )
{
SpecialOutfit.allCheckpoints.remove( this );
}
}
public boolean known()
{
// For use with "try with resource", once we upgrade to a better Java version
synchronized ( SpecialOutfit.class )
{
return SpecialOutfit.allCheckpoints.contains( this );
}
}
}
}
Compilers are unable to understand that the scenario inside Checkpoint.restore(), in which Checkpoint.close() isn't called, simply happens because its result was already achieved. Hence, the warning will be thrown, without being an actual problem.
Edit: spelling
Attachments
Last edited: