Avro
  1. Avro
  2. AVRO-988

Java: Add public, private, and public-deprecated options for SpecificCompiler output

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.2
    • Fix Version/s: 1.7.3
    • Component/s: java
    • Labels:
      None
    • Release Note:
      Adds field visibility options for SpecificCompiler output

      Description

      The specific compiler produces deprecation warnings in both client code and the specific generated classes themselves. The field visibility should be configurable by the user.
      I propose that the SpecificCompiler for the default template allow for a fieldVisibility option that is one of the below:

      • 'public' fields are public, and not deprecated, this is the 1.5.x behavior
      • 'public-deprecated' fields are public, and marked @Deprecated. This is the default behavior in 1.6.x
      • 'private' fields are private. This may be the default in the future.
      1. AVRO-988.patch
        13 kB
        Jeff Kolesky

        Activity

        Hide
        Jeff Kolesky added a comment -

        This patch adds a fieldVisibility field to SpecificCompiler, updates the templates to reference that setting, and exposes it as a configuration option through the Maven plugin.

        Show
        Jeff Kolesky added a comment - This patch adds a fieldVisibility field to SpecificCompiler, updates the templates to reference that setting, and exposes it as a configuration option through the Maven plugin.
        Hide
        Doug Cutting added a comment -

        This looks good to me. I'll commit it soon unless someone objects.

        Show
        Doug Cutting added a comment - This looks good to me. I'll commit it soon unless someone objects.
        Hide
        Scott Carey added a comment -

        Overall looks good. One minor detail:

          protected SpecificCompiler.FieldVisibility getFieldVisibility() {
            if (this.fieldVisibility == null) {
              return SpecificCompiler.FieldVisibility.PUBLIC_DEPRECATED;
            }
            String visibility = this.fieldVisibility.toUpperCase();
            for (SpecificCompiler.FieldVisibility enumValue : SpecificCompiler.FieldVisibility.values()) {
              if (enumValue.name().equals(visibility)) {
                return enumValue;
              }
            }
            return SpecificCompiler.FieldVisibility.PUBLIC_DEPRECATED;
          }
        

        Prefer:

          protected SpecificCompiler.FieldVisibility getFieldVisibility() {
            try {
              String upper = String.valueOf(this.fieldVisibility).trim().toUpperCase();
              return SpecificCompiler.FieldVisibility.valueOf(upper);
            } catch (IllegalArgumentException e) {
              return SpecificCompiler.FieldVisibility.PUBLIC_DEPRECATED;
            }
          }
        
        Show
        Scott Carey added a comment - Overall looks good. One minor detail: protected SpecificCompiler.FieldVisibility getFieldVisibility() { if ( this .fieldVisibility == null ) { return SpecificCompiler.FieldVisibility.PUBLIC_DEPRECATED; } String visibility = this .fieldVisibility.toUpperCase(); for (SpecificCompiler.FieldVisibility enumValue : SpecificCompiler.FieldVisibility.values()) { if (enumValue.name().equals(visibility)) { return enumValue; } } return SpecificCompiler.FieldVisibility.PUBLIC_DEPRECATED; } Prefer: protected SpecificCompiler.FieldVisibility getFieldVisibility() { try { String upper = String .valueOf( this .fieldVisibility).trim().toUpperCase(); return SpecificCompiler.FieldVisibility.valueOf(upper); } catch (IllegalArgumentException e) { return SpecificCompiler.FieldVisibility.PUBLIC_DEPRECATED; } }
        Hide
        Jeff Kolesky added a comment -

        I made the change an added it to the larger patch in AVRO-1209.

        Show
        Jeff Kolesky added a comment - I made the change an added it to the larger patch in AVRO-1209 .
        Hide
        Doug Cutting added a comment -

        I committed this. Thanks, Jeff!

        Show
        Doug Cutting added a comment - I committed this. Thanks, Jeff!

          People

          • Assignee:
            Jeff Kolesky
            Reporter:
            Scott Carey
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development