Raphael Nguyen created THRIFT-6135:
--------------------------------------

             Summary: Suppress this-escape Warning from Java 21+
                 Key: THRIFT-6135
                 URL: https://issues.apache.org/jira/browse/THRIFT-6135
             Project: Thrift
          Issue Type: Bug
          Components: Java - Compiler
    Affects Versions: 0.23.0
            Reporter: Raphael Nguyen


h1. Versions

Thrift 0.23.0 (I believe this still happens on the newly released 0.24.0)

Java 25 (this warning is observable for any Java version 21+)
h1. Description

As of 0.23.0, the java classes generated by the thrift compiler triggers the 
{{this-escape}} warning when compiled on java 21+. When compiled with 
{{-Werror}} flag on, these warnings fail the compilation.

The warning triggers when a constructor calls a public non-final instance 
method. Specifically, I've observed it trigger on the argument class of a 
service endpoint with a boolean argument. In such a case, the generated 
argument class constructor to set the boolean field with the 
{{set<ArgumentName>IsSet()}} method, which triggers the warning. E.g.:
{code:java}
// Thrift interface
service MyService {
  MyResponse myEndPoint(
    1: bool booleanArgument,
    2: string stringArgument
  )
}

// generated java code
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})public 
class MyService {
  //...
  @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})  
public static class myEndPoint_args implements 
org.apache.thrift.TBase<myEndPoint_args, myEndPoint_args._Fields>, 
java.io.Serializable, Cloneable, Comparable<myEndPoint_args>   {
    //...
    public myEndPoint_args() {
    }

    public myEndPoint_args(
      boolean booleanArgument,
      java.lang.String stringArgument)
    {
      this();
      // the following line triggers this-escape warning
      setBooleanArgumentIsSet(booleanArgument);
      this.stringArgument = stringArgument;
    }
    //...
  }
  //...
}{code}
h1. Expected

The generated code should compile with no warning under java 21+.
h1. Potential Solution

Would it be possible to add {{this-escape}} to the list of warnings already 
being suppressed by the generated classes. This would make for a greatly 
improved user experience on java 21+. Thank you very much for considering this 
issue.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to