Skip to content

Commit ee34e2c

Browse files
committed
Add -Djava.library.path=. to force System.loadLibrary("attach") failure
java.library.path on Windows auto-includes all PATH directories, not just java.home\bin. Even after removing bin\attach.dll, another copy (or the jre\bin version) is reachable via PATH, causing System.loadLibrary("attach") to succeed with the wrong DLL — which doesn't export tempPath(). Fix: pass -Djava.library.path=. to explicitly override java.library.path with just the current directory (no attach.dll). Combined with the JRE copy controlling sun.boot.library.path, both sys_paths and usr_paths are clear of attach.dll, so: - reproduce job: System.loadLibrary("attach") fails -> UnsatisfiedLinkError - verify-fix job: loadAttachLibrary() catches it, falls back to System.load($JAVA_HOME/jre/bin/attach.dll) -> "Loaded attach" -> works Also simplify setup steps by removing the now-unnecessary JDK bin removal. https://claude.ai/code/session_01R7dUoeZm6vv7V1HGKVuseV
1 parent 6aa7f5e commit ee34e2c

1 file changed

Lines changed: 22 additions & 49 deletions

File tree

.github/workflows/reproduce-issue-7.yml

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ jobs:
9292
- name: Build unfixed jar
9393
run: mvn -B package -DskipTests
9494

95-
- name: Create JRE copy without attach.dll; remove from JDK bin
95+
- name: Create JRE copy without attach.dll
9696
shell: pwsh
9797
run: |
98-
# 1. Copy $JAVA_HOME\jre so we have a java.exe whose sun.boot.library.path
99-
# (= copy's bin/) does not contain attach.dll.
98+
# Copy $JAVA_HOME\jre so we have a java.exe whose sun.boot.library.path
99+
# (= copy's bin/) does not contain attach.dll.
100+
# JAVA_HOME remains on the original JDK so tools.jar and the fix's
101+
# fallback path ($JAVA_HOME/jre/bin/attach.dll) are both intact.
100102
$src = "$env:JAVA_HOME_JDK\jre"
101103
$dst = "$env:TEMP\jre-no-attach"
102104
Write-Host "Copying $src -> $dst ..."
@@ -105,43 +107,25 @@ jobs:
105107
Write-Host "Removed attach.dll from JRE copy."
106108
echo "JRE_NO_ATTACH=$dst" >> $env:GITHUB_ENV
107109
108-
# 2. Also remove attach.dll from $JAVA_HOME\bin.
109-
# That directory is on PATH, so on Windows it ends up in java.library.path.
110-
# If we leave it there, System.loadLibrary("attach") finds a different
111-
# (incomplete) attach.dll from bin\ — not the full jre\bin version —
112-
# which loads but then fails on tempPath() with UnsatisfiedLinkError
113-
# instead of the ServiceConfigurationError we want to reproduce.
114-
# We keep $JAVA_HOME\jre\bin\attach.dll intact for the fix's fallback.
115-
$jdkBinAttach = "$env:JAVA_HOME_JDK\bin\attach.dll"
116-
if (Test-Path $jdkBinAttach) {
117-
Remove-Item $jdkBinAttach -Force
118-
Write-Host "Removed attach.dll from JDK bin\ (was on PATH)."
119-
} else {
120-
Write-Host "No attach.dll in JDK bin\ — nothing to remove."
121-
}
122-
123-
Write-Host ""
124110
Write-Host "Final state:"
125-
Write-Host " JRE copy bin\attach.dll : $(Test-Path "$dst\bin\attach.dll")"
126-
Write-Host " JDK bin\attach.dll : $(Test-Path "$jdkBinAttach")"
127-
Write-Host " JDK jre\bin\attach.dll : $(Test-Path "$env:JAVA_HOME_JDK\jre\bin\attach.dll")"
111+
Write-Host " JRE copy bin\attach.dll : $(Test-Path "$dst\bin\attach.dll")"
112+
Write-Host " JDK jre\bin\attach.dll : $(Test-Path "$env:JAVA_HOME_JDK\jre\bin\attach.dll")"
128113
129114
- name: Run unfixed jar with no-attach JRE java.exe
130115
shell: pwsh
131116
run: |
132-
# JAVA_HOME must point to JDK so AgentAttach can find tools.jar.
133-
# We run with the copied JRE's java.exe which has no attach.dll in
134-
# its sun.boot.library.path.
117+
# sun.boot.library.path = JRE-copy bin (no attach.dll, controls sys_paths).
118+
# -Djava.library.path=. overrides the PATH-derived java.library.path so that
119+
# usr_paths is just "." (current dir, no attach.dll).
120+
# Together these ensure System.loadLibrary("attach") finds nothing, reproducing
121+
# the issue regardless of whatever else is on PATH.
135122
$env:JAVA_HOME = $env:JAVA_HOME_JDK
136123
$jar = Get-Item target\extract-tls-secrets-*.jar | Select-Object -First 1
137124
Write-Host "java.exe : $env:JRE_NO_ATTACH\bin\java.exe"
138125
Write-Host "JAVA_HOME: $env:JAVA_HOME"
139-
& "$env:JRE_NO_ATTACH\bin\java.exe" -jar $jar.FullName list 2>&1 |
126+
& "$env:JRE_NO_ATTACH\bin\java.exe" "-Djava.library.path=." -jar $jar.FullName list 2>&1 |
140127
Tee-Object -FilePath output-unfixed.txt
141128
Write-Host "Exit code: $LASTEXITCODE"
142-
# Reset exit code: java failure is expected here; the next step checks the output.
143-
# GitHub Actions' PowerShell runner appends `exit $LASTEXITCODE` so we must
144-
# clear it to prevent the step itself from failing before the assert runs.
145129
$LASTEXITCODE = 0
146130
147131
- name: Assert issue #7 is reproduced
@@ -198,7 +182,7 @@ jobs:
198182
- name: Build fixed jar (unmodified source)
199183
run: mvn -B package -DskipTests
200184

201-
- name: Create JRE copy without attach.dll; remove from JDK bin
185+
- name: Create JRE copy without attach.dll
202186
shell: pwsh
203187
run: |
204188
$src = "$env:JAVA_HOME_JDK\jre"
@@ -209,55 +193,44 @@ jobs:
209193
Write-Host "Removed attach.dll from JRE copy."
210194
echo "JRE_NO_ATTACH=$dst" >> $env:GITHUB_ENV
211195
212-
# Remove from JDK bin\ too — same reason as in reproduce job.
213-
$jdkBinAttach = "$env:JAVA_HOME_JDK\bin\attach.dll"
214-
if (Test-Path $jdkBinAttach) {
215-
Remove-Item $jdkBinAttach -Force
216-
Write-Host "Removed attach.dll from JDK bin\ (was on PATH)."
217-
}
218-
219196
Write-Host "Final state:"
220197
Write-Host " JRE copy bin\attach.dll : $(Test-Path "$dst\bin\attach.dll")"
221-
Write-Host " JDK bin\attach.dll : $(Test-Path "$jdkBinAttach")"
222198
Write-Host " JDK jre\bin\attach.dll : $(Test-Path "$env:JAVA_HOME_JDK\jre\bin\attach.dll")"
223199
224200
- name: Verify preconditions
225201
shell: pwsh
226202
run: |
227203
$jdkJreAttach = "$env:JAVA_HOME_JDK\jre\bin\attach.dll"
228-
$jdkBinAttach = "$env:JAVA_HOME_JDK\bin\attach.dll"
229204
$fakeAttach = "$env:JRE_NO_ATTACH\bin\attach.dll"
230205
$fail = $false
231206
if (-not (Test-Path $jdkJreAttach)) {
232207
Write-Error "Precondition FAILED: JDK jre\bin has no attach.dll at $jdkJreAttach"
233208
$fail = $true
234209
}
235-
if (Test-Path $jdkBinAttach) {
236-
Write-Error "Precondition FAILED: attach.dll still in JDK bin\ at $jdkBinAttach (on PATH — would be found before fix)"
237-
$fail = $true
238-
}
239210
if (Test-Path $fakeAttach) {
240211
Write-Error "Precondition FAILED: attach.dll still in copied JRE at $fakeAttach"
241212
$fail = $true
242213
}
243214
if ($fail) { exit 1 }
244215
Write-Host "Preconditions OK:"
245-
Write-Host " JDK jre\bin\attach.dll present : $jdkJreAttach"
246-
Write-Host " JDK bin\attach.dll absent (not on PATH)"
247-
Write-Host " Copied JRE bin\attach.dll absent"
216+
Write-Host " JDK jre\bin\attach.dll present (fix fallback target)"
217+
Write-Host " Copied JRE bin\attach.dll absent (sys_paths will miss it)"
248218
249219
- name: Run fixed jar with no-attach JRE java.exe
250220
shell: pwsh
251221
run: |
222+
# Same isolation as reproduce job:
223+
# sun.boot.library.path = JRE-copy bin (no attach.dll)
224+
# -Djava.library.path=. overrides PATH-based java.library.path
225+
# The fix's loadAttachLibrary() catches the UnsatisfiedLinkError and
226+
# falls back to System.load($JAVA_HOME/jre/bin/attach.dll).
252227
$env:JAVA_HOME = $env:JAVA_HOME_JDK
253228
$jar = Get-Item target\extract-tls-secrets-*.jar | Select-Object -First 1
254229
Write-Host "java.exe : $env:JRE_NO_ATTACH\bin\java.exe"
255230
Write-Host "JAVA_HOME: $env:JAVA_HOME"
256-
& "$env:JRE_NO_ATTACH\bin\java.exe" -jar $jar.FullName list 2>&1 |
231+
& "$env:JRE_NO_ATTACH\bin\java.exe" "-Djava.library.path=." -jar $jar.FullName list 2>&1 |
257232
Tee-Object -FilePath output-fixed.txt
258233
Write-Host "Exit code: $LASTEXITCODE"
259-
# Reset so the step doesn't fail due to the PowerShell runner's exit-code check.
260-
# The actual success/failure is determined by the next assert step.
261234
$LASTEXITCODE = 0
262235
263236
- name: Assert fix works

0 commit comments

Comments
 (0)