Better error message for missing return types need to be public classes or interfaces

Signed-off-by: niclas <niclas@hedhman.org>

(cherry picked from commit 0f58a7d)
Signed-off-by: niclas <niclas@hedhman.org>
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java
index 427cff0..026a4e1 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java
@@ -27,13 +27,14 @@
 import org.apache.polygene.api.common.ConstructionException;
 import org.apache.polygene.api.composite.ConstructorDescriptor;
 import org.apache.polygene.api.composite.InvalidCompositeException;
-import org.apache.polygene.api.util.AccessibleObjects;
 import org.apache.polygene.api.util.HierarchicalVisitor;
 import org.apache.polygene.api.util.VisitableHierarchy;
 import org.apache.polygene.runtime.injection.DependencyModel;
 import org.apache.polygene.runtime.injection.InjectedParametersModel;
 import org.apache.polygene.runtime.injection.InjectionContext;
 
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
+
 /**
  * JAVADOC
  */
@@ -46,7 +47,7 @@
 
     public ConstructorModel( Constructor<?> constructor, InjectedParametersModel parameters )
     {
-        this.constructor = AccessibleObjects.accessible( constructor );
+        this.constructor = accessible( constructor );
         this.parameters = parameters;
     }
 
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java
index 7d96abf..bf750e9 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java
@@ -21,6 +21,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 
 /**
  * JAVADOC
@@ -38,7 +39,21 @@
         }
         catch( InvocationTargetException e )
         {
-            throw cleanStackTrace( e.getTargetException(), proxy, method );
+            Throwable targetException = e.getTargetException();
+            if( targetException instanceof IllegalAccessError )
+            {
+                // We get here if any of the return types or parameters are not public. This is probably due to
+                // the _Stub class ends up in a different classpace than the original mixin. We intend to fix this in
+                // 3.1 or 3.2
+                if( !Modifier.isPublic( method.getReturnType().getModifiers() ) )
+                {
+                    String message = "Return types must be public: " + method.getReturnType().getName();
+                    IllegalAccessException illegalAccessException = new IllegalAccessException( message );
+                    illegalAccessException.initCause( e.getTargetException() );
+                    throw cleanStackTrace( illegalAccessException, proxy, method );
+                }
+            }
+            throw cleanStackTrace( targetException, proxy, method );
         }
         catch( Throwable e )
         {