You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/04 14:30:28 UTC

[GitHub] [beam] damccorm opened a new issue, #19930: Default methods not allowed in PipelineOptions

damccorm opened a new issue, #19930:
URL: https://github.com/apache/beam/issues/19930

   If I create a class that extends PipelineOptions and contains a default method, the PipelineOptionsFactory will throw an exception because all non-static, non-synthetic and non-known methods need to have a getter and a setter.
   
   For example, these PipelineOptions
   ```
   
   public interface MyOptions extends PipelineOptions {
     void setValue(String s);
     String getValue();
   
   
     default List<String> getValues() {
        return Arrays.asList(getValue().split(","));
      }
   }
   ```
   
   will throw an exception in org.apache.beam.sdk.options.PipelineOptionsFactory.java:
   ```
   
   private static void validateMethodsAreEitherBeanMethodOrKnownMethod(
       Class<? extends PipelineOptions>
   iface,
       Class<? extends PipelineOptions> klass,
       List<PropertyDescriptor> descriptors) {
   
   ...
   //
   Verify that no additional methods are on an interface that aren't a bean property.
   // Because methods
   can have multiple declarations, we do a name-based comparison
   // here to prevent false positives.
   SortedSet<Method>
   unknownMethods = new TreeSet<>(MethodComparator.INSTANCE);
   unknownMethods.addAll(
       Sets.filter(
   
          Sets.difference(Sets.newHashSet(iface.getMethods()), knownMethods),
           Predicates.and(
   
              NOT_SYNTHETIC_PREDICATE,
               input -> !knownMethodsNames.contains(input.getName()),
   
              NOT_STATIC_PREDICATE)));
   checkArgument(
       unknownMethods.isEmpty(),
       "Methods %s
   on [%s] do not conform to being bean properties.",
       FluentIterable.from(unknownMethods).transform(ReflectHelpers.METHOD_FORMATTER),
   
      iface.getName());
   }
   ```
   
   Having a NOT_DEFAULT_PREDICATE in addition to the other predicates would allow 
   ```
   
   private static final Predicate<Method> NOT_DEFAULT_PREDICATE = input -> !input.isDefault();
   
   ```
   
   Seems like it would do the trick.
   
   Imported from Jira [BEAM-8669](https://issues.apache.org/jira/browse/BEAM-8669). Original Jira may contain additional context.
   Reported by: chrisstockton.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org