Skip to content

THRIFT-6522: Reject non-string message fields in Java exceptions - #4134

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

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

Conversation

@slachiewicz

Copy link
Copy Markdown
Member

Jira: THRIFT-6522

An exception field named message generates getMessage(), which overrides Throwable.getMessage() and must return String. With any other type (a bool gets isMessage() and is fine) the generated Java never compiled. The Java generator now stops with an error naming the exception and the field, before writing any file.

IDL that used such a field produced uncompilable Java before, so no working build breaks.

Verified: thrift_compiler_tests "*named message" → fails on master (an i32 message field is not reported), 2 of 2 test cases pass on this branch; the full suite passes (42 test cases).

  • Did you create an Apache Jira ticket?
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-6522: describe my issue"?
  • Did you squash your changes to a single commit?
  • Did you do your best to avoid breaking changes? Only IDL whose generated Java could not compile is rejected.

@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 01:35
Copilot AI balanced review requested due to automatic review settings November 8, 2026 01:35

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

No issues found. Checked for bugs and CLAUDE.md compliance.

Two suggestions, below the bar for an issue but verified:

  • The "Build and run compiler tests on their own" step of cmake.yml does not build the new test. That step configures compiler/cpp/tests directly, where Java is still OFF, so java/*.c* is never globbed. Only the combined build in the same job runs it, because compiler/cpp/CMakeLists.txt turns THRIFT_COMPILER_JAVA on. compiler/cpp/tests/README.md asks to set the language to ON when adding tests, as is done for kotlin and the other languages with a test directory.

THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" OFF)
THRIFT_ADD_COMPILER(java "Enable compiler for Java" OFF)
THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" OFF)

  • With java:option_type, exception E { 1: optional string message } still gets a getter that cannot override Throwable.getMessage(). The 0.25.0 compiler emits public org.apache.thrift.Option<java.lang.String> getMessage(), and java.util.Optional<java.lang.String> with option_type=jdk8. The new check accepts any string field named message, so that combination still yields Java that does not compile. It never compiled before either, so this is no regression, just one more case the check could reject.

if (is_exception) {
// The getter of a field named "message" must override Throwable.getMessage(), which returns
// String; a bool field gets isMessage() instead, and binary returns byte[].
for (t_field* field : tstruct->get_members()) {
t_type* type = get_true_type(field->get_type());
if (get_cap_name(field->get_name()) == "Message" && !type->is_bool()
&& !(type->is_string() && !type->is_binary())) {
throw "exception " + tstruct->get_name() + ": field '" + field->get_name()
+ "' must be a string or bool, because its getter would clash with"
" Throwable.getMessage()";
}
}

🤖 Generated with Claude Code

Client: java

An exception field named "message" generates getMessage(), which must
override Throwable.getMessage() and so return String. Any other type
(bool excepted, it gets isMessage()) produced Java that never compiled.
The generator now fails with a message naming the exception and field
before writing the file.

Tested with t_java_generator_message_field_tests: i32, list and binary are
rejected, string and bool still generate.

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.

@mergeable mergeable Bot added the build and general CI cmake, automake and build system changes label Nov 13, 2026

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

build and general CI cmake, automake and build system changes compiler java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants