Package io.codemodder.codemods
Class PreventFileWriterLeakWithFilesCodemod
java.lang.Object
io.codemodder.javaparser.JavaParserChanger
io.codemodder.SarifPluginJavaParserChanger<com.github.javaparser.ast.expr.ObjectCreationExpr>
io.codemodder.codemods.PreventFileWriterLeakWithFilesCodemod
- All Implemented Interfaces:
io.codemodder.CodeChanger
@Codemod(id="pixee:java/prevent-filewriter-leak-with-nio",
importance=MEDIUM,
reviewGuidance=MERGE_WITHOUT_REVIEW)
public final class PreventFileWriterLeakWithFilesCodemod
extends io.codemodder.SarifPluginJavaParserChanger<com.github.javaparser.ast.expr.ObjectCreationExpr>
Transform calls to
BufferedWriter(Writer)
that have anonymous
FileWriter(File)
in their constructor arguments to use an NIO method
instead. This prevents a file descriptor leak that can occur.-
Field Summary
Fields inherited from class io.codemodder.SarifPluginJavaParserChanger
sarif
Fields inherited from class io.codemodder.javaparser.JavaParserChanger
reporter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.codemodder.javaparser.ChangesResult
onResultFound
(io.codemodder.CodemodInvocationContext context, com.github.javaparser.ast.CompilationUnit cu, com.github.javaparser.ast.expr.ObjectCreationExpr newBufferedWriterCall, com.contrastsecurity.sarif.Result result) Methods inherited from class io.codemodder.SarifPluginJavaParserChanger
shouldRun, visit
Methods inherited from class io.codemodder.javaparser.JavaParserChanger
getDescription, getIndividualChangeDescription, getReferences, getSummary
-
Constructor Details
-
PreventFileWriterLeakWithFilesCodemod
@Inject public PreventFileWriterLeakWithFilesCodemod(@SemgrepScan(ruleId="prevent-filewriter-leak-with-nio") io.codemodder.RuleSarif sarif)
-
-
Method Details
-
onResultFound
public io.codemodder.javaparser.ChangesResult onResultFound(io.codemodder.CodemodInvocationContext context, com.github.javaparser.ast.CompilationUnit cu, com.github.javaparser.ast.expr.ObjectCreationExpr newBufferedWriterCall, com.contrastsecurity.sarif.Result result) - Specified by:
onResultFound
in classio.codemodder.SarifPluginJavaParserChanger<com.github.javaparser.ast.expr.ObjectCreationExpr>
-