Skip to content

Commit e435cfc

Browse files
edburnsCopilot
andcommitted
Replace identity comparison with .equals() for ABSENT_SENTINEL
Use .equals() instead of == for the sentinel check. The sentinel value contains null bytes that cannot appear in real environment variables, making .equals() safe and eliminating the CodeQL string-identity alert. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c4e523e3-9d39-4598-90ec-54d959c44ce8
1 parent 82e2bdc commit e435cfc

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

java/sdk/src/test/java/com/github/copilot/ffi/InProcessEnvGuard.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ public void close() {
120120
List<Map.Entry<String, String>> reversed = new ArrayList<>(saved);
121121
Collections.reverse(reversed);
122122
for (Map.Entry<String, String> entry : reversed) {
123-
// Identity comparison is intentional: ABSENT_SENTINEL is a unique instance
124-
// used to distinguish "env var was absent" from "env var was empty string".
125-
@SuppressWarnings("StringEquality")
126-
boolean wasAbsent = entry.getValue() == ABSENT_SENTINEL; // lgtm[java/reference-equality-on-strings]
127-
String restoreValue = wasAbsent ? null : entry.getValue();
123+
// ABSENT_SENTINEL uses a value ("\0ABSENT\0") impossible in real env vars.
124+
String restoreValue = ABSENT_SENTINEL.equals(entry.getValue()) ? null : entry.getValue();
128125
nativeSetEnv(entry.getKey(), restoreValue);
129126
}
130127
}

0 commit comments

Comments
 (0)