Skip to content

Commit fd4565f

Browse files
edburnsCopilot
andcommitted
Fix CodeQL always-true comparison and string identity alerts
- SessionEventsE2ETest: replace trivially-true size >= 0 assertion with conditional content access (getData() assertion when events present). - InProcessEnvGuard: suppress StringEquality warning on intentional identity comparison with ABSENT_SENTINEL (unique instance used as a null-alternative sentinel to distinguish absent vs empty env vars). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c4e523e3-9d39-4598-90ec-54d959c44ce8
1 parent 1ad2ae0 commit fd4565f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

java/sdk/src/test/java/com/github/copilot/SessionEventsE2ETest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.github.copilot;
66

77
import static org.junit.jupiter.api.Assertions.assertFalse;
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
89
import static org.junit.jupiter.api.Assertions.assertTrue;
910

1011
import java.nio.file.Files;
@@ -184,8 +185,9 @@ void testShouldReceiveSessionEvents_assistantUsageEvent() throws Exception {
184185
// Usage events may or may not be emitted depending on the model/API version
185186
// This test verifies the event handler works when they are emitted
186187
// We don't assert they must be present since it depends on the backend
187-
assertTrue(usageEvents.size() >= 0,
188-
"Usage event handler should not throw (collected " + usageEvents.size() + " events)");
188+
if (!usageEvents.isEmpty()) {
189+
assertNotNull(usageEvents.get(0).getData(), "Usage event should carry data");
190+
}
189191
}
190192
}
191193

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ 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-
String restoreValue = entry.getValue() == ABSENT_SENTINEL ? null : entry.getValue();
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;
127+
String restoreValue = wasAbsent ? null : entry.getValue();
124128
nativeSetEnv(entry.getKey(), restoreValue);
125129
}
126130
}

0 commit comments

Comments
 (0)