Skip to content

8200473: cond? true : false patterns in openjdk#30486

Closed
shunohta wants to merge 3 commits intoopenjdk:masterfrom
shunohta:SHUN_JDK-8200473
Closed

8200473: cond? true : false patterns in openjdk#30486
shunohta wants to merge 3 commits intoopenjdk:masterfrom
shunohta:SHUN_JDK-8200473

Conversation

@shunohta
Copy link
Copy Markdown

@shunohta shunohta commented Mar 29, 2026

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.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8200473: cond? true : false patterns in openjdk (Bug - P5)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30486/head:pull/30486
$ git checkout pull/30486

Update a local copy of the PR:
$ git checkout pull/30486
$ git pull https://git.openjdk.org/jdk.git pull/30486/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30486

View PR using the GUI difftool:
$ git pr show -t 30486

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30486.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label Mar 29, 2026
@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Mar 29, 2026

Hi @shunohta, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user shunohta" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Mar 29, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title JDK-8200473: cond? true : false patterns in openjdk 8200473: cond? true : false patterns in openjdk Mar 29, 2026
@openjdk openjdk bot added security security-dev@openjdk.org nio nio-dev@openjdk.org core-libs core-libs-dev@openjdk.org net net-dev@openjdk.org i18n i18n-dev@openjdk.org labels Mar 29, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Mar 29, 2026

@shunohta The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n
  • net
  • nio
  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@shunohta shunohta force-pushed the SHUN_JDK-8200473 branch 2 times, most recently from 47efc5b to 2a4586d Compare April 7, 2026 16:51
@bridgekeeper bridgekeeper bot removed the oca Needs verification of OCA signatory status label Apr 10, 2026
@shunohta shunohta marked this pull request as ready for review April 11, 2026 08:53
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 11, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 11, 2026

Webrevs

@jaikiran
Copy link
Copy Markdown
Member

@shunohta, the OpenJDK Generative AI policy https://openjdk.org/legal/ai doesn't allow for content generated from LLM to be accepted as a contribution. I see that in your PR description you confirm (through the checkbox) that the content in this PR wasn't generated using LLM, yet the PR description and the changes appear to contradict the claim. These changes cannot be accepted in the current form. Please refer to the https://openjdk.org/legal/ai document for what's allowed and what's not allowed as a contribution.

@shunohta
Copy link
Copy Markdown
Author

I acknowledge that I used an LLM to generate the descriptions and identify patterns, but I manually reviewed all changes.
I will close this pull request, and for future contributions, I will ensure that all development and documentation are done without any AI assistance.

@shunohta shunohta closed this Apr 11, 2026
@pavelrappo
Copy link
Copy Markdown
Member

  1. I'm not sure why the OpenJDK bot removed the OCA label; I cannot see you in census. Have you signed OCA?
  2. I don't see tier1 results for this PR.
  3. Since your PR predates Interim AI Policy announcement, have you carefully read it before accepting it for this PR?

@jaikiran
Copy link
Copy Markdown
Member

I acknowledge that I used an LLM to generate the descriptions and identify patterns, but I manually reviewed all changes. I will close this pull request, and for future contributions, I will ensure that all development and documentation are done without any AI assistance.

Thank you @shunohta. Contributions to the OpenJDK project are always welcome including fixes for starter issues like this one (the project has accepted several such fixes over the years even before Generative AI contributions became common). So feel free to continue to contribute to the project. Apart from the new Generative AI guidelines, the OpenJDK dev guide https://openjdk.org/guide/ has some general guidelines which provide help on how to contribute.

@shunohta shunohta deleted the SHUN_JDK-8200473 branch April 11, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org net net-dev@openjdk.org nio nio-dev@openjdk.org rfr Pull request is ready for review security security-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

3 participants