This is an automated email from the ASF dual-hosted git repository. davidb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push: new 9f29bc8 Convert to Interface without methods - FELIX-6238 new 29ccc55 Merge pull request #9 from stbischof/conv_int_empt 9f29bc8 is described below commit 9f29bc82aa688c38b9b74b79ccd2d50ae0a8abac Author: Stefan Bischof <stbisc...@bipolis.org> AuthorDate: Tue Mar 17 15:24:51 2020 +0100 Convert to Interface without methods - FELIX-6238 --- .../org/osgi/util/converter/ConvertingImpl.java | 6 ++++- .../org/osgi/util/converter/ConverterTest.java | 29 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/converter/converter/src/main/java/org/osgi/util/converter/ConvertingImpl.java b/converter/converter/src/main/java/org/osgi/util/converter/ConvertingImpl.java index fc409d2..c9e3722 100644 --- a/converter/converter/src/main/java/org/osgi/util/converter/ConvertingImpl.java +++ b/converter/converter/src/main/java/org/osgi/util/converter/ConvertingImpl.java @@ -1126,11 +1126,15 @@ class ConvertingImpl extends AbstractSpecifying<Converting> Set<Class< ? >> interfaces = getInterfaces0(cls); outer: for (Iterator<Class< ? >> it = interfaces.iterator(); it.hasNext();) { Class< ? > intf = it.next(); - for (Method method : intf.getMethods()) { + Method[] methods=intf.getMethods(); + for (Method method : methods) { if(method.getDeclaringClass() == intf) { continue outer; } } + if(intf==cls&&methods.length==0) { + continue outer; + } it.remove(); } diff --git a/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java b/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java index 9b4615e..ef00c13 100644 --- a/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java +++ b/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java @@ -1451,11 +1451,40 @@ public class ConverterTest { assertEquals(Integer.valueOf(0), inter.value()); } + @Test + public void testMapToEmptyInterface() throws Exception { + Map<String, Object> map = new HashMap<String, Object>(); + map.put("a", "b"); + EmptyInterface i = Converters.standardConverter().convert(map).to(EmptyInterface.class); + assertNotNull(i); + + EmptyInterface2 j = Converters.standardConverter().convert(map).to(EmptyInterface2.class); + assertNotNull(j); + + EmptyInterface3 k = Converters.standardConverter().convert(map).to(EmptyInterface3.class); + assertNotNull(k); + } + static interface MyIntf2 { String code(); Integer value(); } + static interface EmptyInterface + { + } + + static interface EmptyInterface2 extends EmptyInterface + { + } + static interface NonEmptyInterface + { + int a(); + } + + static interface EmptyInterface3 extends NonEmptyInterface + { + } static class MyClass2 { private final String value; public MyClass2(String v) {