Skip to content

Commit 5620908

Browse files
docs: add resource ownership documentation for @Owning/@NotOwning annotations
Document resource ownership semantics in Javadocs for methods and parameters annotated with Eclipse's @owning and @NotOwning annotations: - @owning: caller owns returned resource, must close it - @NotOwning: caller does not own resource, must not close it Updated files across cli-processor, core, databind, and schemagen modules.
1 parent a3fb760 commit 5620908

12 files changed

Lines changed: 35 additions & 5 deletions

File tree

cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ public CLIProcessor(@NonNull String exec, @NonNull Map<String, IVersionInfo> ver
164164
* the version info to display when the version option is provided
165165
* @param outputStream
166166
* the output stream to write to, or {@code null} to use the default
167-
* console
167+
* console. The caller retains ownership of this stream and is
168+
* responsible for closing it.
168169
*/
169170
@SuppressWarnings("resource")
170171
public CLIProcessor(@NonNull String exec, @NonNull Map<String, IVersionInfo> versionInfos,
@@ -278,6 +279,8 @@ static void handleNoColor() {
278279

279280
/**
280281
* Get the output stream used for writing CLI output.
282+
* <p>
283+
* The caller does not own this stream and must not close it.
281284
*
282285
* @return the output stream
283286
*/

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/antlr/ParseTreePrinter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class ParseTreePrinter {
2828
* Construct a new concrete syntax tree (CST) printer.
2929
*
3030
* @param outputStream
31-
* the stream to print to
31+
* the stream to print to. The caller retains ownership of this stream
32+
* and is responsible for closing it.
3233
*/
3334
public ParseTreePrinter(@NotOwning @NonNull PrintStream outputStream) {
3435
this.outputStream = outputStream;

core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/ParallelValidationConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ private ParallelValidationConfig(@Nullable ExecutorService executor, int threadC
6363
* <p>
6464
* The executor is NOT shut down by {@link #close()}; the caller retains
6565
* ownership.
66+
* <p>
67+
* The caller owns the returned configuration and is responsible for closing it.
6668
*
6769
* @param executor
6870
* the executor service to use for parallel tasks
@@ -81,6 +83,8 @@ public static ParallelValidationConfig withExecutor(@NonNull ExecutorService exe
8183
* Create configuration that creates an internal thread pool.
8284
* <p>
8385
* The internal pool is shut down when {@link #close()} is called.
86+
* <p>
87+
* The caller owns the returned configuration and is responsible for closing it.
8488
*
8589
* @param threadCount
8690
* number of threads (must be &gt;= 1)

core/src/main/java/gov/nist/secauto/metaschema/core/util/AutoCloser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public final class AutoCloser<T, E extends Exception> implements AutoCloseable {
3232
/**
3333
* Adapt the the provided {@code resource} to be {@link AutoCloseable}, using a
3434
* provided closer {@code lambda}.
35+
* <p>
36+
* The caller owns the returned wrapper and is responsible for closing it.
3537
*
3638
* @param <T>
3739
* the resource's type
@@ -110,6 +112,8 @@ public interface Closer<T, E extends Exception> {
110112
* <p>
111113
* This is useful for protecting standard streams. i.e. {@link System#out},
112114
* {@link System#err}.
115+
* <p>
116+
* The caller owns the returned stream and is responsible for closing it.
113117
*
114118
* @param out
115119
* the stream to wrap

databind/src/main/java/gov/nist/secauto/metaschema/databind/IBindingContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,14 @@ <CLASS extends IBoundObject> CLASS deepCopy(@NonNull CLASS other, IBoundObject p
456456

457457
/**
458458
* Get a new single use constraint validator.
459+
* <p>
460+
* The caller owns the returned validator and is responsible for closing it to
461+
* release any resources (such as thread pools) when validation is complete.
459462
*
460463
* @param handler
461464
* the validation handler to use to process the validation results
462465
* @param config
463466
* the validation configuration
464-
*
465467
* @return the validator
466468
*/
467469
@SuppressWarnings("resource")

databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/ModuleCompilerHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ private ModuleCompilerHelper() {
4747
/**
4848
* Create a new classloader capable of loading Java classes generated in the
4949
* provided {@code classDir}.
50+
* <p>
51+
* The caller owns the returned class loader and is responsible for closing it.
5052
*
5153
* @param classDir
5254
* the directory where generated Java classes have been compiled

databind/src/main/java/gov/nist/secauto/metaschema/databind/io/IBoundLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ default Format detectFormat(@NonNull URL url) throws IOException {
140140
* <p>
141141
* This method will not close any {@link InputStream} provided by the
142142
* {@link InputSource}, since it does not own the stream.
143+
* <p>
144+
* The caller owns the returned result and is responsible for closing it.
143145
*
144146
* @param is
145147
* an input stream for the resource

databind/src/main/java/gov/nist/secauto/metaschema/databind/io/IParsingContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
public interface IParsingContext<READER, PROBLEM_HANDLER extends IProblemHandler> {
2323
/**
2424
* The parser used for reading data associated with the supported format.
25+
* <p>
26+
* The caller does not own this reader and must not close it.
2527
*
2628
* @return the parser
2729
*/

databind/src/main/java/gov/nist/secauto/metaschema/databind/io/ModelDetector.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@ private IConfiguration<DeserializationFeature<?>> getConfiguration() {
9999
* model.
100100
*
101101
* @param inputStream
102-
* the resource stream to analyze
102+
* the resource stream to analyze. The caller retains ownership of this
103+
* stream and is responsible for closing it.
103104
* @param resource
104105
* the resource being parsed
105106
* @param format
106107
* the expected format of the data to read
107-
* @return the analysis result
108+
* @return the analysis result. The caller owns this result and is responsible
109+
* for closing it.
108110
* @throws IOException
109111
* if an error occurred while reading the resource
110112
*/
@@ -250,6 +252,8 @@ public Class<? extends IBoundObject> getBoundClass() {
250252
/**
251253
* Get an {@link InputStream} that can be used to read the analyzed data from
252254
* the start.
255+
* <p>
256+
* The caller owns this stream and is responsible for closing it.
253257
*
254258
* @return the stream
255259
*/

schemagen/src/main/java/gov/nist/secauto/metaschema/schemagen/AbstractSchemaGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public abstract class AbstractSchemaGenerator<
4242

4343
/**
4444
* Create a new writer to use to write the schema.
45+
* <p>
46+
* The caller owns the returned writer and is responsible for closing it.
4547
*
4648
* @param out
4749
* the {@link Writer} to write the schema content to

0 commit comments

Comments
 (0)