Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5017

Code gen of Generated annotation should work with Java 9+

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 0.13.0
    • Fix Version/s: None
    • Component/s: Java - Library
    • Labels:
      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_)

      { 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; }

      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dlichao Chao Li
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: