Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
0.13.0
-
None
-
None
Description
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);
indent(out) << "@javax.annotation.Generated(value = \"" << autogen_summary() << "\"";
if (undated_generated_annotations_)
else
{ indent(out) << ", date = \"" << (now->tm_year + 1900) << "-" << setfill('0') << setw(2) << (now->tm_mon + 1) << "-" << setfill('0') << setw(2) << now->tm_mday << "\")" << endl; }}