Skip to content

Workspace viewer displays UTF-8 Java source files as garbled text when no charset is specified #26894

@tianyatmq

Description

@tianyatmq

Jenkins and plugins versions report

Environment
Jenkins: 2.528.3
OS: Windows 10 - 10.0
Java: 17.0.19 - Eclipse Adoptium (OpenJDK 64-Bit Server VM)
---
analysis-model-api:13.21.0-945.va_f5a_0b_c1404b_
ant:520.vd082ecfb_16a_9
antisamy-markup-formatter:173.v680e3a_b_69ff3
apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83
apache-httpcomponents-client-5-api:5.6.1-195.v65ffe15189a_d
asm-api:9.10.1-216.va_9256d3b_844b_
audit-trail:436.vc0d1e79fc5a_3
bootstrap5-api:5.3.8-895.v4d0d8e47fea_d
bouncycastle-api:2.30.1.84-291.v9f17b_21896e2
branch-api:2.1280.v0d4e5b_b_460ef
build-timeout:1.40
caffeine-api:3.2.3-194.v31a_b_f7a_b_5a_81
checks-api:415.vf022234a_931d
cloudbees-folder:6.1100.ve9eed61d16c4
cmakebuilder:4.1.1
commons-lang3-api:3.20.0-109.ve43756e2d2b_4
commons-text-api:1.15.0-218.va_61573470393
credentials:1496.vf6821f162d4e
credentials-binding:725.ve52b_2328a_fde
dark-theme:652.vea_da_dfea_e769
data-tables-api:2.3.7-1534.v539d4edf109d
display-url-api:2.217.va_6b_de84cc74b_
durable-task:671.v340ff7959010
echarts-api:6.0.0-1247.vf3e35a_c1813f
eddsa-api:0.3.0.1-29.v67e9a_1c969b_b_
email-ext:2038.v7b_8817a_499d9
font-awesome-api:7.2.0-965.ve3840b_696418
forensics-api:3.1832.va_1179842528b_
git:5.10.1
git-client:6.6.0
github:1.46.0.1
github-api:1.330-492.v3941a_032db_2a_
github-branch-source:1917.v9ee8a_39b_3d0d
gradle:2.19.1244.v1f9866817fec
gson-api:2.14.0-201.v8eefe5515533
instance-identity:203.v15e81a_1b_7a_38
ionicons-api:94.vcc3065403257
jackson-annotations2-api:2.22-19.v10a_a_582ea_26e
jackson2-api:2.21.2-436.v29efdb_7418ff
jackson3-api:3.1.4-81.v804303fd947a_
jakarta-activation-api:2.1.4-1
jakarta-mail-api:2.1.5-1
jakarta-xml-bind-api:4.0.9-19.v2b_a_5b_44d9a_1c
javax-activation-api:1.2.0-8
javax-mail-api:1.6.2-11
jaxb:2.3.9-143.v5979df3304e6
jdk-tool:83.v417146707a_3d
jjwt-api:0.13.0-141.vd58b_a_9592b_6c
job-import-plugin:143.145.v48f9a_a_6ff384
jobConfigHistory:1356.ve360da_6c523a_
joda-time-api:2.14.2-193.v422b_efce56e0
jquery3-api:3.7.1-619.vdb_10e002501a_
json-api:20260522-217.v0b_18b_8cd4672
json-path-api:3.0.0-218.vcd4dd1355de2
jsoup:1.22.2-95.vc5d00f1eb_42d
junit:1369.v15da_00283f06
ldap:807.809.vd3a_4e5e4ec98
localization-support:1.41.v186a_c1569458
localization-zh-cn:371.v23851f835d6b_
mailer:534.v1b_36f5864073
matrix-auth:3.2.10
matrix-project:870.v9db_fcfc2f45b_
metrics:4.2.37-494.v06f9a_939d33a_
mina-sshd-api-common:2.17.1-187.v0341274c2905
mina-sshd-api-core:2.17.1-187.v0341274c2905
naginator:1.556.v14d723a_109a_c
okhttp-api:5.3.2-200.vedb_720a_cf1f8
pam-auth:1.12
pipeline-build-step:584.vdb_a_2cc3a_d07a_
pipeline-github-lib:65.v203688e7727e
pipeline-graph-analysis:254.v0f63a_a_447dca_
pipeline-groovy-lib:798.v5cc688825312
pipeline-input-step:551.vdff487c5998c
pipeline-milestone-step:152.v6e22b_8cfc66c
pipeline-model-api:2.2289.v6f731d0a_02da_
pipeline-model-definition:2.2289.v6f731d0a_02da_
pipeline-model-extensions:2.2289.v6f731d0a_02da_
pipeline-rest-api:2.41
pipeline-stage-step:345.va_96187909426
pipeline-stage-tags-metadata:2.2289.v6f731d0a_02da_
pipeline-stage-view:2.41
plain-credentials:199.v9f8e1f741799
plugin-util-api:6.1192.v30fe6e2837ff
prism-api:1.30.0-717.vb_f8360844b_53
resource-disposer:0.25
role-strategy:867.vd09254229f9b_
scm-api:728.vc30dcf7a_0df5
script-security:1402.v94c9ce464861
sidebar-link:2.5.0
snakeyaml-api:2.5-149.v72471e9c6371
snakeyaml-engine-api:3.0.1-5.vd98ea_ff3b_92e
ssh-credentials:372.va_250881b_08cd
ssh-slaves:3.1097.v868116049892
sshd:3.384.vc89b_5e138cf9
structs:362.va_b_695ef4fdf9
theme-manager:346.v06cca_64c6a_37
thinBackup:2.1.4
timestamper:1.30
token-macro:477.vd4f0dc3cb_cf1
trilead-api:2.284.v1974ea_324382
variant:70.va_d9f17f859e0
warnings-ng:12.10012.v753ff0d0363a_
woodstox-core-api:7.1.1-1.v4d297985f397
workflow-aggregator:608.v67378e9d3db_1
workflow-api:1384.vdc05a_48f535f
workflow-basic-steps:1098.v808b_fd7f8cf4
workflow-cps:4331.v9d06ed4658ff
workflow-durable-task-step:1479.v56e587f413a_7
workflow-job:1571.1580.v18e46842c125
workflow-multibranch:821.vc3b_4ea_780798
workflow-scm-step:466.va_d69e602552b_
workflow-step-api:724.v538c2362b_dfb_
workflow-support:1015.v785e5a_b_b_8b_22
ws-cleanup:0.49

What Operating System are you using (both controller, and any agents involved in the problem)?

Windows10 22H2

Reproduction steps

Workspace Java files are displayed with garbled UTF-8 characters in browser (missing charset?)

Jenkins and system information

  • Jenkins: 2.528.3
  • Java: Eclipse Temurin JDK 17
  • OS: Windows Server (Chinese locale)
  • Browser: Google Chrome
  • Jenkins installed as Windows Service

Problem

When viewing Java source files directly from the Jenkins Workspace page, Chinese characters are displayed as garbled text.

Example:

Expected:

// 用户中心模块

Actual:

// ��中�模�

The source file itself is UTF-8 encoded and displays correctly in:

  • Android Studio
  • Git repository (GitLab/GitHub)
  • Local editors

Only the Jenkins Workspace file viewer shows garbled characters.

What I have verified

JVM encoding

Script Console:

System.getProperty("file.encoding")

Result:

UTF-8

Workspace file encoding

The Java file stored in the Jenkins workspace is confirmed to be UTF-8 and displays correctly when opened locally on the Jenkins server.

Browser information

Opening the workspace file:

http://<jenkins>/job/.../ws/path/to/File.java

Browser console:

document.contentType

Result:

text/plain

Browser console:

document.characterSet

Result:

GBK

If I manually force UTF-8 using a Chrome encoding extension, all Chinese characters display correctly.

This suggests that:

  • File content is correct
  • JVM encoding is correct
  • Browser is decoding the response using GBK

MIME type check

Script Console:

import jenkins.model.Jenkins

def ctx = Jenkins.instance.servletContext

println ctx.getMimeType("test.java")
println ctx.getMimeType("test.txt")
println ctx.getMimeType("test.xml")
println ctx.getMimeType("test.properties")

Results:

text/plain
text/plain
application/xml
null

Question

Should Jenkins Workspace file responses include an explicit charset (for example charset=UTF-8) when serving text files such as:

  • .java
  • .kt

Could this be a regression or limitation in the current DirectoryBrowserSupport implementation?

I noticed an older issue related to UTF-8 rendering problems in archived files (JENKINS-28676), and I wonder if this workspace viewer behavior is related.

Any guidance would be appreciated.

Expected Results

UTF-8 encoded source files should be displayed correctly in the Jenkins Workspace viewer.

Chinese and other non-ASCII characters should be rendered properly without requiring any browser extensions or manual character encoding changes.

The response for text-based files (e.g. .java, .kt) should explicitly specify UTF-8 encoding when appropriate.

Actual Results

UTF-8 encoded Java source files containing Chinese characters are displayed as garbled text in the Workspace viewer.

Example:

Expected:
用户中心模块

Actual:
��中�模�

The source file itself is UTF-8 encoded and displays correctly in Android Studio, Git repository viewers, and local editors.

Browser diagnostics:
Chrome:
document.contentType = "text/plain"
document.characterSet = "GBK"
FireFox
document.contentType = "text/plain"
document.characterSet = "windows-1252"

If the browser encoding is manually forced to UTF-8 using a browser extension, the file is displayed correctly.

Anything else?

No response

Are you interested in contributing a fix?

I am not familiar with the Jenkins core codebase, but I would be happy to help test proposed fixes, provide additional debugging information, and verify behavior on Windows environments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions