You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LexicalPreservingPrinter will remove comments when using ASTTransforms.wrapIntoResource #338
import java.nio.file.Files;
import java.io.File;
import java.io.BufferedWriter;
class A {
void f(File f) {
// first comment
try (BufferedWriter writer = Files.newBufferedWriter(f.toPath())) {
// second comment
System.out.println(1);
// third comment
System.out.println(2);
}
}
}
------------------
import java.nio.file.Files;
import java.io.File;
import java.io.BufferedWriter;
class A{
void f(File f){
try (BufferedWriter writer = Files.newBufferedWriter(f.toPath())) {
System.out.println(1);
System.out.println(2);
}
}
}
Notice how the comments disappears if we print it with the LexicalPreservingPrinter, despite being there if we chose not to use it.
This affects all codemods that uses this transform, mainly those using the ResourceLeakFixer transform: codeql:java/input-resource-leak, codeql:java/output-resource-leak, codeql:java/database-resource-leak, pixee:java/prevent-filewriter-leak-with-nio, pixee:java/resource-leak.
Can't find a workaround for this, at least one that doesn't involve ditching LexicalPreservingPrinter. I've created an Issue for this in JavaParser's github after narrowing it down a bit more. javaparser/javaparser#4376
Activity
nahsra commentedon Apr 9, 2024
👀
Added resource leak transform and general codemod (#339)
andrecsilva commentedon Apr 18, 2024
Can't find a workaround for this, at least one that doesn't involve ditching LexicalPreservingPrinter. I've created an Issue for this in JavaParser's github after narrowing it down a bit more.
javaparser/javaparser#4376