You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/01/29 15:51:17 UTC

[isis] branch master updated: ISIS-2158: ignore classes we cannot load, when intercepting the scan

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 34d56c3  ISIS-2158: ignore classes we cannot load, when intercepting the scan
34d56c3 is described below

commit 34d56c31be32581d930c92cb61f11a56f68c62ff
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Jan 29 16:51:04 2020 +0100

    ISIS-2158: ignore classes we cannot load, when intercepting the scan
    
    instead of throwing, just log a warning
---
 .../core/config/beans/IsisBeanTypeRegistry.java    | 12 +++++--
 .../isis/core/config/beans/TypeMetaData.java       | 38 +++++++++++++++-------
 2 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeRegistry.java b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeRegistry.java
index 973e458..e983dfd 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeRegistry.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeRegistry.java
@@ -111,8 +111,14 @@ public final class IsisBeanTypeRegistry implements IsisComponentScanInterceptor,
     @Override
     public void intercept(TypeMetaData typeMeta) {
         
-        val type = typeMeta.getUnderlyingClass();
-
+        val classOrFailure = typeMeta.getUnderlyingClassOrFailure();
+        
+        if(classOrFailure.isFailure()) {
+            log.warn(classOrFailure.getFailure());
+            return;
+        }
+        
+        val type = classOrFailure.getUnderlyingClass();
         val classification = quickClassify(type);
         
         val delegated = classification.isDelegateLifecycleManagement();
@@ -163,7 +169,7 @@ public final class IsisBeanTypeRegistry implements IsisComponentScanInterceptor,
     // -- HELPER
 
     private void addIntrospectableType(BeanSort sort, TypeMetaData typeMeta) {
-        val type = typeMeta.getUnderlyingClass();
+        val type = typeMeta.getUnderlyingClassOrFailure().getUnderlyingClass();
         synchronized (introspectableTypes) {
             introspectableTypes.put(type, sort);
             
diff --git a/core/config/src/main/java/org/apache/isis/core/config/beans/TypeMetaData.java b/core/config/src/main/java/org/apache/isis/core/config/beans/TypeMetaData.java
index 3043a46..5945d42 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/beans/TypeMetaData.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/beans/TypeMetaData.java
@@ -20,11 +20,11 @@ package org.apache.isis.core.config.beans;
 
 import org.apache.isis.core.commons.internal.base._Strings;
 import org.apache.isis.core.commons.internal.context._Context;
-import org.apache.isis.core.commons.internal.exceptions._Exceptions;
 
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.Setter;
+import lombok.Value;
 import lombok.val;
 
 @RequiredArgsConstructor(staticName = "of")
@@ -53,25 +53,39 @@ final class TypeMetaData {
     private boolean injectable = true;
     
     @Getter(lazy=true)
-    private final Class<?> underlyingClass = resolveClass();
+    private final ClassOrFailure underlyingClassOrFailure = resolveClass();
+    
+    public String getEffectiveBeanName() {
+        return _Strings.isNullOrEmpty(beanNameOverride)
+                ? proposedBeanName 
+                        : beanNameOverride;
+    }
+    
+    // -- HELPER
+    
+    /**
+     * Holds either the class or the failure string when attempting to load by name. 
+     */
+    @Value(staticConstructor = "of")
+    final static class ClassOrFailure {
+        Class<?> underlyingClass;
+        String failure;
+        public boolean isFailure() {
+            return underlyingClass==null;
+        }
+    }
     
     /**
      * @return the underlying class of this TypeMetaData
      */
-    private Class<?> resolveClass() {
+    private ClassOrFailure resolveClass() {
         try {
-            return _Context.loadClass(className);
+            return ClassOrFailure.of(_Context.loadClass(className), null);
         } catch (ClassNotFoundException e) {
-            val msg = String.format("Failed to load class for name '%s'", className);
-            throw _Exceptions.unrecoverable(msg, e);
+            val msg = String.format("Failed to load class for name '%s', throwing %s", className, e);
+            return ClassOrFailure.of(null, msg);
         }
     }
 
-    public String getEffectiveBeanName() {
-        return _Strings.isNullOrEmpty(beanNameOverride)
-                ? proposedBeanName 
-                        : beanNameOverride;
-    }
-
 
 }