# Problem: - Redundant ternary operator patterns such as `<cond> ? true : false` and `<cond> ? false : true` exist in the codebase - Since the condition already evaluates to a `boolean`, the ternary operator is unnecessary
# Analysis: - Since the original ticket was filed (JDK 10), some files have been removed and some patterns have already been fixed - I re-evaluated the list of redundant patterns against the current codebase ## Redundant patterns by module - `src/` — 74 occurrences: java.xml (31), java.desktop (20), java.base (8), others (15) - `test/` — 138 occurrences: test/hotspot (76), test/jdk (52), others (10) # Solution: - Given the wide impact scope across multiple modules, the fixes are partitioned by module to facilitate easier review - This PR addresses redundant patterns within `java.base`, the core module of the JDK ## Changes in java.base (8 files) | No. | File | Line | |-----|------|:----:| | 1 | `share/classes/sun/net/www/protocol/http/NTLMAuthenticationProxy.java` | 45 | | 2 | `share/classes/sun/security/provider/X509Factory.java` | 564 | | 3 | `share/classes/sun/text/DictionaryBasedBreakIterator.java` | 131 | | 4 | `share/classes/jdk/internal/event/SocketReadEvent.java` | 141 | | 5 | `share/classes/java/text/CollationElementIterator.java` | 638 | | 6 | `unix/classes/sun/nio/fs/UnixPath.java` | 705 | | 7 | `share/classes/sun/security/validator/Validator.java` | 268 | | 8 | `share/classes/jdk/internal/icu/lang/UCharacter.java` | 474 | # Testing: This PR performs semantically equivalent cleanups with no behavioral changes. I have verified that all relevant existing `jtreg` tests pass. ## Test mapping | No. | Changed file | Test file | |-----|------------|--------------| | 1 | `NTLMAuthenticationProxy.java` | `test/jdk/sun/net/www/protocol/http/NoNTLM.java` | | 2 | `X509Factory.java` | `test/jdk/sun/security/provider/X509Factory/BadPem.java` | | 3 | `DictionaryBasedBreakIterator.java` | `test/jdk/java/text/BreakIterator/BreakIteratorTest.java` etc. | | 4 | `SocketReadEvent.java` | `test/jdk/jdk/jfr/event/io/TestSocketEvents.java` etc. | | 5 | `CollationElementIterator.java` | `test/jdk/java/text/Collator/IteratorTest.java` etc. | | 6 | `UnixPath.java` | `test/jdk/java/nio/file/Path/PathOps.java` etc. | | 7 | `Validator.java` | `test/jdk/sun/security/validator/EndEntityExtensionCheck.java` etc. | | 8 | `UCharacter.java` | (Comment-only change; no test needed) | #### Notes on verification While verifying the changes against the existing tests, I noticed the following points and addressed them as part of this PR: * **No. 6 UnixPath.java**: For `startsWith()`, I added test cases to `PathOps.java` to cover edge cases like `"//"` or `"///"` (which `normalizeAndCheck()` normalizes to `/`). * **No. 7 Validator.java**: Although `type` is a `String` field, the original code used `==` for reference comparison. I have updated this to use `!Objects.equals()` for a proper value comparison. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - JDK-8200473: Add normalization edge cases to startsWith tests - JDK-8200473: Use Objects.equals() instead of != for String comparison - JDK-8200473: Clean up 'cond ? true : false' patterns in java.base Changes: https://git.openjdk.org/jdk/pull/30486/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=30486&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8200473 Stats: 10 lines in 9 files changed: 2 ins; 0 del; 8 mod Patch: https://git.openjdk.org/jdk/pull/30486.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/30486/head:pull/30486 PR: https://git.openjdk.org/jdk/pull/30486
