Chao Li created THRIFT-5017:
-------------------------------

             Summary: 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


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.3.4#803005)

Reply via email to