[
https://issues.apache.org/jira/browse/BEAM-8669?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17415303#comment-17415303
]
chris stockton commented on BEAM-8669:
--------------------------------------
This does still seem to be an issue. I made the modifications above and I can
at least create an instance of an interface with a default method. However,
the proxy handler doesn't have any code to actually invoke the default method,
so the above code change alone would not actually fix any thing.
A quick search seems to indicate that older versions of Java (8, 9, 10) don't
have a consistent way to reflectively call default methods on interfaces, so
I'm not sure there's an easy way to fix that part.
https://stackoverflow.com/questions/22614746/how-do-i-invoke-java-8-default-methods-reflectively
It doesn't seem like this is a problem affecting very many people and there are
easy enough ways to accomplish the same thing with static interface methods.
> Default methods not allowed in PipelineOptions
> ----------------------------------------------
>
> Key: BEAM-8669
> URL: https://issues.apache.org/jira/browse/BEAM-8669
> Project: Beam
> Issue Type: Bug
> Components: beam-model
> Affects Versions: 2.16.0
> Reporter: chris stockton
> Priority: P3
>
> 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
> {code:java}
> public interface MyOptions extends PipelineOptions {
> void setValue(String s);
> String getValue();
> default List<String> getValues() {
> return Arrays.asList(getValue().split(","));
> }
> }{code}
> will throw an exception in
> org.apache.beam.sdk.options.PipelineOptionsFactory.java:
> {code: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());
> }{code}
> Having a NOT_DEFAULT_PREDICATE in addition to the other predicates would
> allow
> {code:java}
> private static final Predicate<Method> NOT_DEFAULT_PREDICATE = input ->
> !input.isDefault();
> {code}
> Seems like it would do the trick.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)