You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jr...@apache.org on 2008/12/18 21:39:06 UTC
svn commit: r727813 - in /openjpa/trunk:
openjpa-kernel/src/main/java/org/apache/openjpa/enhance/
openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/
openjpa-persis...
Author: jrbauer
Date: Thu Dec 18 12:39:06 2008
New Revision: 727813
URL: http://svn.apache.org/viewvc?rev=727813&view=rev
Log:
OPENJPA-819 Committing fix for NPE and corresponding test case contributed by Dianne Richards.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Animal.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence2.xml (with props)
Modified:
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java?rev=727813&r1=727812&r2=727813&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java Thu Dec 18 12:39:06 2008
@@ -43,6 +43,7 @@
import org.apache.openjpa.util.GeneratedClasses;
import org.apache.openjpa.util.ImplHelper;
import org.apache.openjpa.util.InternalException;
+import org.apache.openjpa.util.MetaDataException;
import org.apache.openjpa.util.UserException;
import serp.bytecode.BCClass;
@@ -133,10 +134,16 @@
// set this before enhancement as well as after since enhancement
// uses a different metadata repository, and the metadata config
- // matters in the enhancement contract. Don't do any warning here,
+ // matters in the enhancement contract. In order to avoid a
+ // NullPointerException, check for no metadata and throw an
+ // exception if none exists. Otherwise, don't do any warning here,
// since we'll issue warnings when we do the final metadata
// reconfiguration at the end of this method.
- configureMetaData(enhancer.getMetaData(), conf, redefine, false);
+ ClassMetaData meta = enhancer.getMetaData();
+ if (meta == null) {
+ throw new MetaDataException(_loc.get("no-meta", cls)).setFatal(true);
+ }
+ configureMetaData(meta, conf, redefine, false);
unspecified = collectRelatedUnspecifiedTypes(enhancer.getMetaData(),
classes, unspecified);
Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties?rev=727813&r1=727812&r2=727813&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties (original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties Thu Dec 18 12:39:06 2008
@@ -16,7 +16,9 @@
# under the License.
copy-no-oid: Cannot copy identity for abstract type "{0}".
-no-meta: No registered metadata for type "{0}".
+no-meta: No registered metadata for type "{0}". This can happen if this \
+ class has not been annotated as a persistent entity or specified in the \
+ persistence unit (ex: in the orm.xml).
bad-getter: Missing getter for property "{1}" in type "{0}".
bad-setter: Missing setter for property "{1}" in type "{0}".
bad-field: Missing field for property "{1}" in type "{0}".
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Animal.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Animal.java?rev=727813&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Animal.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Animal.java Thu Dec 18 12:39:06 2008
@@ -0,0 +1,28 @@
+/*
+ * 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.openjpa.persistence.simple;
+
+// This class specifically does NOT have @Entity specified for it since it is
+// used by the TestMissingMetaData test case.
+public class Animal {
+ private String name;
+
+ public Animal() {
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Animal.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java?rev=727813&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java Thu Dec 18 12:39:06 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.openjpa.persistence.simple;
+
+import org.apache.openjpa.persistence.ArgumentException;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+// This test case extends TestCase directly instead of SingleEMTestCase with the
+// corresponding setup() method because that scheme goes down a different code
+// path and doesn't test the intended code change.
+public class TestMissingMetaData extends TestCase {
+ private OpenJPAEntityManagerFactory emf;
+
+ public void setUp() {
+ // This test case uses a different persistence xml file because
+ // modifying the current persistence.xml file with a bad class would
+ // cause the TestEnhancementWithMultiplePUs test case to fail.
+ emf = OpenJPAPersistence.createEntityManagerFactory(
+ "test-missing-metadata", "persistence2.xml");
+ }
+
+ public void testMissingMetaData() {
+ String msg =
+ "No registered metadata for type " +
+ "\"class org.apache.openjpa.persistence.simple.Animal\".";
+ try {
+ emf.createEntityManager();
+ fail("didn't receive expected ArgumentException - " + msg);
+ } catch (Exception e) {
+ assertEquals(ArgumentException.class,e.getClass());
+ assertTrue(e.getMessage().startsWith(msg));
+ }
+ }
+
+ public void tearDown() {
+ emf.close();
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(TestMissingMetaData.class);
+
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestMissingMetaData.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence2.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence2.xml?rev=727813&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence2.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence2.xml Thu Dec 18 12:39:06 2008
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ version="1.0">
+
+ <persistence-unit name="test-missing-metadata">
+ <class>org.apache.openjpa.persistence.simple.Animal</class>
+ </persistence-unit>
+
+</persistence>
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence2.xml
------------------------------------------------------------------------------
svn:eol-style = native