Skip to content

Commit 84fc415

Browse files
committed
🚧 Remove Log Statement
This behavior is consistent with the original intention of the codemod.
1 parent b45867e commit 84fc415

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

‎core-codemods/src/main/java/io/codemodder/codemods/SensitiveDataLoggingCodemod.java‎

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.fasterxml.jackson.annotation.JsonProperty;
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import com.fasterxml.jackson.databind.ObjectReader;
9-
import com.github.javaparser.StaticJavaParser;
109
import com.github.javaparser.ast.CompilationUnit;
1110
import com.github.javaparser.ast.stmt.Statement;
1211
import com.theokanning.openai.completion.chat.*;
@@ -72,15 +71,11 @@ public CodemodFileScanningResult visit(
7271
throw new UncheckedIOException("Couldn't perform sensitivity analysis", e);
7372
}
7473
if (analysis.isSensitiveAndDirectlyLogged()) {
75-
String newStatement = analysis.newStatement();
76-
if (newStatement != null && !newStatement.isBlank()) {
77-
Statement newStmt = StaticJavaParser.parseStatement(newStatement);
78-
statement.get().replace(newStmt);
79-
80-
String analysisText = analysis.isSensitiveAnalysisText();
81-
CodemodChange change = CodemodChange.from(startLine, analysisText);
82-
changes.add(change);
83-
}
74+
// remove the log statement altogether
75+
statement.get().remove();
76+
String analysisText = analysis.isSensitiveAnalysisText();
77+
CodemodChange change = CodemodChange.from(startLine, analysisText);
78+
changes.add(change);
8479
}
8580
}
8681
return CodemodFileScanningResult.from(changes, List.of());
@@ -100,9 +95,8 @@ private SensitivityAndFixAnalysis performSensitivityAnalysis(
10095
sensitive_analysis_text: a careful, thorough analysis of whether the data is sensitive (specifically a password, session ID, security token, SSN, etc -- not a username)
10196
is_data_directly_logged: a careful, thorough analysis of whether the data is definitely and directly logged (e.g., not just passed to another method inside to the scope, unless that's a method that obviously returns the given string)
10297
is_it_sensitive_and_directly_logged: a boolean dictating whether it is sensitive and definitely and directly logged
103-
new_line_to_replace: if sensitive and directly logged, the statement on line %d that should replace it -- remember to correctly JSON escape this value
10498
"""
105-
.formatted(startLine, codeSnippet, startLine);
99+
.formatted(startLine, codeSnippet);
106100

107101
ChatCompletionRequest request =
108102
ChatCompletionRequest.builder()
@@ -143,9 +137,6 @@ private interface SensitivityAndFixAnalysis {
143137

144138
/** Whether the statement logs sensitive data. */
145139
boolean isSensitiveAndDirectlyLogged();
146-
147-
/** The new statement with which to replace the old. */
148-
String newStatement();
149140
}
150141

151142
private static class SensitivityAndFixAnalysisDTO implements SensitivityAndFixAnalysis {
@@ -159,9 +150,6 @@ private static class SensitivityAndFixAnalysisDTO implements SensitivityAndFixAn
159150
@JsonProperty("is_it_sensitive_and_directly_logged")
160151
private boolean isSensitiveAndDirectlyLogged;
161152

162-
@JsonProperty("new_line_to_replace")
163-
private String newLineToReplace;
164-
165153
@Override
166154
public String isSensitiveAnalysisText() {
167155
return sensitiveAnalysisText;
@@ -171,11 +159,6 @@ public String isSensitiveAnalysisText() {
171159
public boolean isSensitiveAndDirectlyLogged() {
172160
return isSensitiveAndDirectlyLogged;
173161
}
174-
175-
@Override
176-
public String newStatement() {
177-
return newLineToReplace;
178-
}
179162
}
180163

181164
@Override

‎core-codemods/src/test/java/io/codemodder/codemods/SensitiveDataLoggingCodemodTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.codemodder.plugins.llm.test.LLMVerifyingCodemodTestMixin;
44
import io.codemodder.plugins.llm.test.OpenAIIntegrationTest;
55
import io.codemodder.testutils.Metadata;
6-
import org.junit.jupiter.api.Disabled;
76

87
@Metadata(
98
codemodType = SensitiveDataLoggingCodemod.class,

0 commit comments

Comments
 (0)