Default methods not allowed in PipelineOptions
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start in org.apache.beam.sdk.options.PipelineOptionsFactory.java, especially validateMethodsAreEitherBeanMethodOrKnownMethod and the predicates used to identify unknown methods. Reproduce the reported default-method case, then verify that default methods are accepted while non-bean, non-static, non-synthetic, and non-known methods still fail validation.
Written by the indexing model from the issue text.
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<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. Original Jira may contain additional context.
Reported by: chrisstockton.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 4.7k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 194
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/beam
-
java P3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug failing test flake P2 pinned tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug io P3 pinned pubsub
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
awaiting triage bug P2 stale website
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100