Skip to content

THRIFT-4191: Drop constant presence flags from Java equals() - #4151

Open
slachiewicz wants to merge 1 commit into
apache:masterfrom
slachiewicz:THRIFT-4191
Open

slachiewicz wants to merge 1 commit into
apache:masterfrom
slachiewicz:THRIFT-4191

Conversation

@slachiewicz

Copy link
Copy Markdown
Member

Jira: THRIFT-4191

For fields that are neither optional nor nullable, the generated Java equals() declared this_present_x and that_present_x as constant true and guarded the comparison with them, which Coverity reports as dead code. Such fields are now compared directly; optional and nullable fields keep the isset-based guard.

Verified: generated code for ThriftTest.thrift and a mixed struct differs only in the 45 collapsed blocks; new TestGeneratedEquals fails on the old output and passes on the new; spotlessCheck clean.

  • Did you create an Apache Jira ticket?
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-4191: describe my issue"?
  • Did you squash your changes to a single commit?
  • Did you do your best to avoid breaking changes? Equality semantics are unchanged.

@mergeable mergeable Bot added java Pull requests that update Java code compiler labels Nov 8, 2026
@slachiewicz
slachiewicz marked this pull request as ready for review November 8, 2026 02:59
Copilot AI balanced review requested due to automatic review settings November 8, 2026 02:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Jens-G

Jens-G commented Nov 13, 2026

Copy link
Copy Markdown
Member

Code review

Found 1 issue:

  1. testNoConstantPresenceFlagsForPrimitives reads the generated Simple.java from build/gen-java/…, relative to the test JVM's working directory, which is lib/java. The CMake JavaTest passes -Pbuild.dir=${CMAKE_CURRENT_BINARY_DIR}/build, and environment.gradle moves buildDir there. So in an out-of-tree CMake build, such as build/docker/scripts/cmake.sh with its cmake_build directory, the generated file is not where the test looks. The test then throws NoSuchFileException, or reads a stale copy that an earlier in-tree build left behind. I traced this through the build files and did not run it; no CI job runs the Java tests through CMake. Passing genSrc to the test JVM as a system property, as unitTests.gradle already does for the trust store, would remove the dependency on the working directory.

public void testNoConstantPresenceFlagsForPrimitives() throws Exception {
Path src = Paths.get("build", "gen-java", "thrift", "test", "Simple.java");
String code = new String(Files.readAllBytes(src), StandardCharsets.UTF_8);

🤖 Generated with Claude Code

Client: java

For fields that are neither optional nor nullable, the generated equals()
declared this_present_x and that_present_x as constant true and guarded the
comparison with them, which Coverity reports as DEADCODE. Such fields are now
compared directly; optional and nullable fields keep the isset-based guard.
Behavior is unchanged: ThriftTest.thrift and a mixed struct generate the same
code except for the 45 collapsed blocks. TestGeneratedEquals covers equality
semantics and fails on the old output.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants