You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2018/07/31 12:19:03 UTC

svn commit: r1837138 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/corespi/scanner/ test/java/org/apache/webbeans/corespi/ test/java/org/apache/webbeans/corespi/scanner/

Author: rmannibucau
Date: Tue Jul 31 12:19:03 2018
New Revision: 1837138

URL: http://svn.apache.org/viewvc?rev=1837138&view=rev
Log:
OWB-1250 log at fine level the no class def found error of anonymous classes

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/corespi/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/corespi/scanner/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscoveryTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java?rev=1837138&r1=1837137&r2=1837138&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java Tue Jul 31 12:19:03 2018
@@ -409,7 +409,14 @@ public abstract class AbstractMetaDataDi
                     }
                     catch (NoClassDefFoundError e)
                     {
-                        if (logger.isLoggable(Level.WARNING))
+                        if (isAnonymous(className))
+                        {
+                            if (logger.isLoggable(Level.FINE))
+                            {
+                                logger.log(Level.FINE, OWBLogConst.WARN_0018, new Object[]{className, e.toString()});
+                            }
+                        }
+                        else if (logger.isLoggable(Level.WARNING))
                         {
                             logger.log(Level.WARNING, OWBLogConst.WARN_0018, new Object[]{className, e.toString()});
                         }
@@ -423,6 +430,24 @@ public abstract class AbstractMetaDataDi
         return beanClassesPerBda;
     }
 
+    private boolean isAnonymous(final String className)
+    {
+        final int start = className.lastIndexOf('$');
+        if (start <= 0)
+        {
+            return false;
+        }
+        try
+        {
+            Integer.parseInt(className.substring(start + 1));
+            return true;
+        }
+        catch (final NumberFormatException nfe)
+        {
+            return false;
+        }
+    }
+
     /* (non-Javadoc)
      * @see org.apache.webbeans.corespi.ScannerService#getBeanClasses()
      */

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscoveryTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscoveryTest.java?rev=1837138&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscoveryTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscoveryTest.java Tue Jul 31 12:19:03 2018
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.corespi.scanner;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Method;
+
+import org.junit.Test;
+
+public class AbstractMetaDataDiscoveryTest
+{
+    @Test
+    public void isAnonymous() throws Exception
+    {
+        final AbstractMetaDataDiscovery mock = new AbstractMetaDataDiscovery()
+        {
+            @Override
+            protected void configure()
+            {
+                // no-op
+            }
+        };
+        final Method mtd = AbstractMetaDataDiscovery.class.getDeclaredMethod("isAnonymous", String.class);
+        mtd.setAccessible(true);
+        assertFalse(Boolean.class.cast(mtd.invoke(mock, AbstractMetaDataDiscoveryTest.class.getName())));
+        assertTrue(Boolean.class.cast(mtd.invoke(mock, AbstractMetaDataDiscoveryTest.class.getName() + "$1")));
+        assertTrue(Boolean.class.cast(mtd.invoke(mock, AbstractMetaDataDiscoveryTest.class.getName() + "$1$2")));
+        assertTrue(Boolean.class.cast(mtd.invoke(mock, AbstractMetaDataDiscoveryTest.class.getName() + "$15$222")));
+    }
+}