From 6f43ce7d40f545a2fd88f0feb752aab16985157c Mon Sep 17 00:00:00 2001 From: "Kevin W. Sutter" Date: Thu, 27 Sep 2007 16:36:48 +0000 Subject: [PATCH] OPENJPA-385. Committing changes for both 1.0.x and 1.1.0 to properly skip and optionally log malformed .class files. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@580087 13f79535-47bb-0310-9956-ffa450edef68 --- .../meta/ClassAnnotationMetaDataFilter.java | 24 ++++++++++++++++++- .../PersistenceMetaDataFactory.java | 7 ++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassAnnotationMetaDataFilter.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassAnnotationMetaDataFilter.java index 139210be0..a6ee36b40 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassAnnotationMetaDataFilter.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassAnnotationMetaDataFilter.java @@ -20,6 +20,9 @@ package org.apache.openjpa.lib.meta; import java.io.IOException; +import org.apache.openjpa.lib.log.Log; +import org.apache.openjpa.lib.util.Localizer; + import serp.bytecode.lowlevel.ConstantPoolTable; /** @@ -33,6 +36,10 @@ import serp.bytecode.lowlevel.ConstantPoolTable; public class ClassAnnotationMetaDataFilter implements MetaDataFilter { private final String[] _annos; + + private static final Localizer _loc = Localizer.forPackage + (ClassAnnotationMetaDataFilter.class); + private Log _log = null; /** * Constructor; supply annotation to match against. @@ -86,9 +93,16 @@ public class ClassAnnotationMetaDataFilter implements MetaDataFilter { idx += 4 + table.readInt(idx); } } catch (ArrayIndexOutOfBoundsException e) { + /* + * This ArrayIndexOutOfBoundsException indicates an incorrectly + * formed .class file. We will eat the exception, log a trace + * message (if a log exists), and return "false" to indicate there + * was no match. + */ Error cfe = new ClassFormatError(rsrc.getName()); cfe.initCause(e); - throw cfe; + if (_log != null && _log.isTraceEnabled()) + _log.trace(_loc.get("class-arg", rsrc.getName()), cfe); } return false; } @@ -184,4 +198,12 @@ public class ClassAnnotationMetaDataFilter implements MetaDataFilter { } return skipped; } + + public Log getLog() { + return _log; + } + + public void setLog(Log _log) { + this._log = _log; + } } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java index 665aea56c..29a1e3a74 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java @@ -374,8 +374,11 @@ public class PersistenceMetaDataFactory @Override protected MetaDataFilter newMetaDataFilter() { - return new ClassAnnotationMetaDataFilter(new Class[]{ - Entity.class, Embeddable.class, MappedSuperclass.class }); + ClassAnnotationMetaDataFilter camdf = new ClassAnnotationMetaDataFilter( + new Class[] { Entity.class, Embeddable.class, + MappedSuperclass.class }); + camdf.setLog(log); + return camdf; } /**