Default methods not allowed in PipelineOptions
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 4.7k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 196
Description
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 getValues() {
return Arrays.asList(getValue().split(","));
}
}
```
will throw an exception in org.apache.beam.sdk.options.PipelineOptionsFactory.java:
```
private static void validateMethodsAreEitherBeanMethodOrKnownMethod(
Class
iface,
Class klass,
List 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
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 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.
Contributor guide
Assessment
This issue has not been assessed yet.