[ 
https://issues.apache.org/jira/browse/THRIFT-5017?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18112786#comment-18112786
 ] 

Sylwester Lachiewicz edited comment on THRIFT-5017 at 9/8/26 1:45 PM:
----------------------------------------------------------------------

The generator emits {{@javax.annotation.Generated}} by default, and 
{{@jakarta.annotation.Generated}} under the {{jakarta_annotations}} option 
([t_java_generator.cc:5861|https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_java_generator.cc#L5861]).
 Neither is the JDK 9+ location this ticket names — 
{{javax.annotation.processing.Generated}} is never emitted — and both need a 
third-party jar on the compile classpath, which is the workaround the 
description already discounts. {{java:generated_annotations=suppress}} 
sidesteps the error by emitting nothing. Reopening; what the default should 
emit is still open.


was (Author: slachiewicz):
The generator emits {{@jakarta.annotation.Generated}} or 
{{@javax.annotation.Generated}} depending on the target 
([compiler/cpp/src/thrift/generate/t_java_generator.cc|https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_java_generator.cc]
 lines 5861-5863). Resolving as Fixed.

> Code gen of Generated annotation should work with Java 9+
> ---------------------------------------------------------
>
>                 Key: THRIFT-5017
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5017
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Library
>    Affects Versions: 0.13.0
>            Reporter: Chao Li
>            Priority: Major
>
> In JDK 8, class "Generated" is at "javax.annotation.Generated". But after 9+, 
> it has been moved to "javax.annotation.processing.Generated".
> [https://docs.oracle.com/javase/8/docs/api/javax/annotation/Generated.html]
> [https://docs.oracle.com/javase/9/docs/api/javax/annotation/processing/Generated.html]
>  
> Current java generator always use first package import thus when generated 
> code is compiled with Java 9+, it will result in compiling error.
> There is workaround: import 3rd party javax.annotation-api
>  
> Issue is in t_java_generator::generate_javax_generated_annotation in 
> [https://github.com/apache/thrift/blob/b3745eea10cde93957882df56ef21f05f5e3cf6b/compiler/cpp/src/thrift/generate/t_java_generator.cc]
>  
> Suggest fix is to use a switch to decide to use which package.
>  
> void t_java_generator::generate_javax_generated_annotation(ostream& out) {
>  time_t seconds = time(NULL);
>  struct tm* now = localtime(&seconds);
>  {color:#ff8b00}indent(out) << "@javax.annotation.Generated(value = \"" << 
> autogen_summary() << "\"";{color}
>  if (undated_generated_annotations_) {
>  out << ")" << endl;
>  } else {
>  indent(out) << ", date = \"" << (now->tm_year + 1900) << "-" << setfill('0') 
> << setw(2)
>  << (now->tm_mon + 1) << "-" << setfill('0') << setw(2) << now->tm_mday
>  << "\")" << endl;
>  }
> }



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

Reply via email to