[BUG][code-analyzer] 5.16.0 skips Apex classes that use multi-line string literals (''') without failing: bundled PMD 7.26.0 cannot parse them (fixed in PMD 7.27.0)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- java, typescript
Hướng nghiên cứu
Start with the code-analyzer-pmd-engine 0.46.0 dependency and its bundled java-lib folder, including pmd-apex-7.26.0.jar and apex-parser-5.0.0.jar. Run the provided sf code-analyzer command against both sample classes; done means the bundled parser scans MultilineLiteral.cls and reports its violation, with parse failures no longer silently omitted.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Have you tried to resolve this issue yourself first?
- I confirm I have gone through the above steps and still have an issue to report.
Bug Description
Code Analyzer 5.16.0 cannot read an Apex class that uses a multi-line string literal (the ''' text block that Apex added in Summer '26). PMD reports a parse error for that file and leaves it out of the scan, but the run still exits 0. Because the file never parses, no PMD rule can check it, security rules included, and nothing fails.
The parse error is printed to the console as an engine error. It does not appear among the violations, so the results file and the summary do not show it. A CI gate that does not use --severity-threshold passes while one or more classes went unchecked.
The cause is the PMD version Code Analyzer bundles. code-analyzer-pmd-engine 0.46.0 ships pmd-apex-7.26.0.jar, and that parser does not understand '''. PMD fixed this in 7.27.0 (pmd/pmd#6887, apex-parser 5.0.0 to 5.1.0), and the bundled java-lib folder still carries apex-parser-5.0.0.jar. Standalone PMD 7.28.0 parses the same file and reports its violations. Code Analyzer needs to bundle PMD 7.27.0 or later. (Issues #1293 and #1380 were the same kind of gap, a parser behind the Apex language, for the ?? operator.)
Steps To Reproduce
-
Create an empty folder with a
classesfolder inside it. -
Add
classes/MultilineLiteral.cls:public class MultilineLiteral { public static String build() { String body = ''' first line second line '''; System.debug(body); return body; } } -
Add
classes/ConcatenatedLiteral.cls, the same class written without the'''literal:public class ConcatenatedLiteral { public static String build() { String body = 'first line\n' + 'second line\n'; System.debug(body); return body; } } -
From that folder, run:
sf code-analyzer run --workspace . --rule-selector pmd:AvoidDebugStatements --output-file results.json echo $?
What happens: the exit code is 0 and results.json holds one violation, for ConcatenatedLiteral.cls line 6. MultilineLiteral.cls has the same System.debug call on line 9, but it is not reported. The console shows (paths shortened, timestamp kept):
Error: Engine 'pmd' [7:9:26.207]:
PMD issued a processing error for file '.../classes/MultilineLiteral.cls':
ParseException: Parse exception:
com.google.summit.SummitAST$ParseException: Failed to parse .../classes/MultilineLiteral.cls:
Syntax error at 5:24: missing ';' at ''\n first line\n second line\n ''
Syntax error at 8:13: extraneous input '''' expecting ';'
For comparison, standalone PMD 7.28.0 on the same folder reports both violations:
pmd check -d classes -R category/apex/performance.xml/AvoidDebugStatements -f text
classes/ConcatenatedLiteral.cls:6: AvoidDebugStatements: Avoid debug statements since they impact on performance
classes/MultilineLiteral.cls:9: AvoidDebugStatements: Avoid debug statements since they impact on performance
Expected Behavior
- Code Analyzer bundles a PMD release whose Apex parser supports multi-line string literals, so these files are scanned like any other.
- Until then, a file PMD cannot parse should be visible in the results (for example as a violation or a failed run), not only as console output while the run exits 0. This is the same silent-pass shape as #2087.
Operating System
macOS 27.0.1, Apple Silicon
Salesforce CLI Version
@salesforce/cli/2.151.7 darwin-arm64 node-v24.20.0
Code Analyzer Plugin (code-analyzer) Version
code-analyzer 5.16.0 (code-analyzer-core 0.53.0, code-analyzer-pmd-engine 0.46.0, PMD 7.26.0)
Node Version
v22.22.3
Java Version
openjdk version "27" 2026-09-15
Python Version
No response
Additional Context (Screenshots, Files, etc)
Multi-line string literals shipped in Summer '26. A team that adopts them loses Code Analyzer coverage for those classes without any warning.
Workaround
Avoid ''' literals in Apex and join ordinary quoted strings with '\n' instead.
Urgency
High
- Ngôn ngữ chính
- TypeScript
- Star
- 241
- Fork
- 51
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của forcedotcom/code-analyzer
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
forcedotcom/code-analyzer#2094 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
forcedotcom/code-analyzer#2093 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
forcedotcom/code-analyzer#2091 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
forcedotcom/code-analyzer#2090 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
forcedotcom/code-analyzer#2104 ·
Tất cả issue của forcedotcom/code-analyzer
Issue tương tự
-
Table: Space fires onActivate in single-selection mode — the reference doc and the JSDoc disagreeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
sidorares/react-x11-components#764 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
backnotprop/plannotator#1840 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
JoviDeCroock/pracht#432 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: CNN en Espanol SDĐang mởapproved check:passed streams:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Hardware attribute name "app Connection Support" has inconsistent casingCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
walletbeat/walletbeat#1628 ·
Maintainer thường phản hồi trong vòng 1 ngày