felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1855240 - in /felix/trunk/converter/converter/src: main/java/org/osgi/util/converter/CustomConverterImpl.java test/java/org/osgi/util/converter/ConverterTest.java
Date Mon, 11 Mar 2019 15:04:32 GMT
Author: davidb
Date: Mon Mar 11 15:04:32 2019
New Revision: 1855240

URL: http://svn.apache.org/viewvc?rev=1855240&view=rev
Log:
FELIX-6008 ErrorHandlers should be applied in reverse order

Modified:
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/CustomConverterImpl.java
    felix/trunk/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java

Modified: felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/CustomConverterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/CustomConverterImpl.java?rev=1855240&r1=1855239&r2=1855240&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/CustomConverterImpl.java
(original)
+++ felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/CustomConverterImpl.java
Mon Mar 11 15:04:32 2019
@@ -181,13 +181,13 @@ class CustomConverterImpl implements Int
 				}
 
 				Object result = del.to(type, c);
-				if (result != null && Proxy.isProxyClass(result.getClass()) && errorHandlers.size()
> 0) {
-				    return wrapErrorHandling(result);
+				if (result != null && Proxy.isProxyClass(result.getClass()) && getErrorHandlers(c).size()
> 0) {
+				    return wrapErrorHandling(result, c);
 				} else {
 				    return result;
 				}
 			} catch (Exception ex) {
-				for (ConverterFunction eh : errorHandlers) {
+				for (ConverterFunction eh : getErrorHandlers(c)) {
 					try {
 						Object handled = eh.apply(object, type);
 						if (handled != ConverterFunction.CANNOT_HANDLE)
@@ -204,7 +204,23 @@ class CustomConverterImpl implements Int
 			}
 		}
 
-		private Object wrapErrorHandling(final Object wrapped) {
+        private List<ConverterFunction> getErrorHandlers(Converter converter) {
+            List<ConverterFunction> handlers = new ArrayList<>();
+
+            if (converter instanceof CustomConverterImpl) {
+                CustomConverterImpl cconverter = (CustomConverterImpl) converter;
+                handlers.addAll(cconverter.errorHandlers);
+
+                Converter nextDel = cconverter.delegate;
+                handlers.addAll(getErrorHandlers(nextDel));
+            }
+
+            handlers.addAll(errorHandlers);
+
+            return handlers;
+        }
+
+		private Object wrapErrorHandling(final Object wrapped, final InternalConverter c) {
 		    final Class<?> cls = wrapped.getClass();
 		    return Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), new InvocationHandler()
{
                 @Override
@@ -228,7 +244,7 @@ class CustomConverterImpl implements Int
                     try {
                         return method.invoke(wrapped, args);
                     } catch (Exception ex) {
-                        for (ConverterFunction eh : errorHandlers) {
+                        for (ConverterFunction eh : getErrorHandlers(c)) {
                             try {
                                 Object handled = eh.apply(wrapped, method.getGenericReturnType());
                                 if (handled != ConverterFunction.CANNOT_HANDLE)

Modified: felix/trunk/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java?rev=1855240&r1=1855239&r2=1855240&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java
(original)
+++ felix/trunk/converter/converter/src/test/java/org/osgi/util/converter/ConverterTest.java
Mon Mar 11 15:04:32 2019
@@ -18,7 +18,6 @@ package org.osgi.util.converter;
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.osgi.framework.Version;
 import org.osgi.util.converter.MyDTO.Count;
@@ -477,7 +476,7 @@ public class ConverterTest {
         assertEquals(123, i.value());
     }
 
-    @Test @Ignore("Not yet implemented")
+    @Test
     public void testMultipleCustomErrorHandling() {
         ConverterBuilder cb1 = converter.newConverterBuilder();
         ConverterFunction func1 = new ConverterFunction() {



Mime
View raw message