[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-1365) NPE AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372) when trying to load a class defined in a signed/sealed JAR

David Cox (JIRA) noreply at atlassian.com
Sun Jun 10 10:34:04 EDT 2007


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1365?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

David Cox updated HHH-1365:
---------------------------

    Attachment: hibernate-hack.jar

I've had this problem several times over the years. The problem was the that the generated proxy classes ended up in the same package as signed classes which they are proxying. You can change this in CGLIB using a custom naming policy to make the proxy classes in a different package. The problem is that setting that is not very easy. My first hack was to actually tweak the CGLIBLazyInitializer hibernate class. That was distasteful in that I had to replace the class file in the jar. This second solution seems to be better. I made copies of the CBLIBLazyInitializer and CGLIBProxyFactory, calling them SignSafe***. I then subclassed PojoTuplizer which uses the CGLIB-hibernate classes. Instead my SignSafeTuplizer uses the SignSafe proxy classes. You just package these with your app and configure your class to use the custom tuplizer (see attached Customer.java).
I hope this prevents anybody else from going through this again. The only potential downside of this solution is if there is a java package access restriction in the original class because the proxy will be in a different package.

> NPE AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372) when trying to load a class defined in a signed/sealed JAR
> ----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-1365
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1365
>             Project: Hibernate3
>          Issue Type: Bug
>    Affects Versions: 3.1
>         Environment: Java1.5.06 Ant1.7alpha, hibernate 3.1
>            Reporter: Steve Loughran
>            Priority: Minor
>         Attachments: cglib-src-2.1_3.patch, hibernate-hack.jar
>
>
> I'm testing what happens to hibernate when running against a signed JAR. The answer is: most tests pass. What fails is this test (Apache 2.0 license, BTW)
>     public void testDetachedObject() throws Exception {
>         Event event = createTestEvent();
>         session.save(event);
>         session.flush();
>         closeSession();
>         //here the event is detached.
>         //we change it outside an operation.
>         String text = "modified";
>         event.setText(text);
>         session = getSessionFactory().openSession();
>         Event merged=(Event) session.merge(event);
>         assertEquals(event, merged);
>         session.flush();
>         closeSession();
>         session = getSessionFactory().openSession();
>         Event loaded = (Event) session.load(Event.class, event.getKey());
>         assertEquals(text, loaded.getText());
>         assertEquals(event, loaded);
>     }
> the session.load operation is failing, with the short stack trace of:
> java.lang.NullPointerException
> at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
> at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
> at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
> at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
> at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
> at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
> at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)
> at org.hibernate.impl.SessionImpl.load(SessionImpl.java:781)
> at d1.persist.test.SessionTest.testDetachedObject(SessionTest.java:155)
> The root cause is probably contained in the info that gets printed when the session starts up, complaining that things cant be added to sealed classes
>    [junit] 2261 ERROR org.hibernate.proxy.BasicLazyInitializer  - CGLIB Enhancement failed: d1.persist.Event
>     [junit] net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
>     [junit] 	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
>     [junit] 	at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
>     [junit] 	at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
>     [junit] 	at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:126)
>     [junit] 	at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
>     [junit] 	at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
>     [junit] 	at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:131)
>     [junit] 	at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
>     [junit] 	at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
>     [junit] 	at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:257)
>     [junit] 	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
>     [junit] 	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
>     [junit] 	at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
>     [junit] 	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:215)
>     [junit] 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1154)
>     [junit] 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:375)
>     [junit] 	at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:533)
>     [junit] 	at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:109)
>     [junit] 	at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:155)
>     [junit] 	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:82)
>     [junit] 	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
>     [junit] 	at d1.persist.PersistTools.createManagerFactory(PersistTools.java:82)
>     [junit] 	at d1.persist.PersistTools.createDefaultManagerFactory(PersistTools.java:76)
>     [junit] 	at d1.persist.test.Ejb3TestBase.setUp(Ejb3TestBase.java:27)
>     [junit] 	at junit.framework.TestCase.runBare(TestCase.java:125)
>     [junit] 	at junit.framework.TestResult$1.protect(TestResult.java:106)
>     [junit] 	at junit.framework.TestResult.runProtected(TestResult.java:124)
>     [junit] 	at junit.framework.TestResult.run(TestResult.java:109)
>     [junit] 	at junit.framework.TestCase.run(TestCase.java:118)
>     [junit] 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
>     [junit] 	at junit.framework.TestSuite.run(TestSuite.java:203)
>     [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:328)
>     [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:736)
>     [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:605)
>     [junit] Caused by: java.lang.reflect.InvocationTargetException
>     [junit] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     [junit] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     [junit] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     [junit] 	at java.lang.reflect.Method.invoke(Method.java:585)
>     [junit] 	at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
>     [junit] 	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
>     [junit] 	... 33 more
>     [junit] Caused by: java.lang.SecurityException: class "d1.persist.Event$$EnhancerByCGLIB$$55c8eae8_2"'s signer information does not match signer information of other classes in the same package
>     [junit] 	at java.lang.ClassLoader.checkCerts(ClassLoader.java:775)
>     [junit] 	at java.lang.ClassLoader.preDefineClass(ClassLoader.java:487)
>     [junit] 	at java.lang.ClassLoader.defineClass(ClassLoader.java:614)
>     [junit] 	... 39 more
>     [junit] 2262 WARN  org.hibernate.tuple.PojoEntityTuplizer  - could not create proxy factory for:d1.persist.Event
>     [junit] org.hibernate.HibernateException: CGLIB Enhancement failed: d1.persist.Event
>     [junit] 	at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:132)
>     [junit] 	at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
>     [junit] 	at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
>     [junit] 	at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:131)
>     [junit] 	at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
>     [junit] 	at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
>     [junit] 	at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:257)
>     [junit] 	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
>     [junit] 	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
>     [junit] 	at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
>     [junit] 	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:215)
>     [junit] 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1154)
>     [junit] 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:375)
>     [junit] 	at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:533)
>     [junit] 	at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:109)
>     [junit] 	at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:155)
>     [junit] 	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:82)
>     [junit] 	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
>     [junit] 	at d1.persist.PersistTools.createManagerFactory(PersistTools.java:82)
>     [junit] 	at d1.persist.PersistTools.createDefaultManagerFactory(PersistTools.java:76)
>     [junit] 	at d1.persist.test.Ejb3TestBase.setUp(Ejb3TestBase.java:27)
>     [junit] 	at junit.framework.TestCase.runBare(TestCase.java:125)
>     [junit] 	at junit.framework.TestResult$1.protect(TestResult.java:106)
>     [junit] 	at junit.framework.TestResult.runProtected(TestResult.java:124)
>     [junit] 	at junit.framework.TestResult.run(TestResult.java:109)
>     [junit] 	at junit.framework.TestCase.run(TestCase.java:118)
>     [junit] 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
>     [junit] 	at junit.framework.TestSuite.run(TestSuite.java:203)
>     [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:328)
>     [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:736)
>     [junit] 	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:605)
>     [junit] Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
>     [junit] 	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
>     [junit] 	at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
>     [junit] 	at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
>     [junit] 	at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:126)
>     [junit] 	... 30 more
>     [junit] Caused by: java.lang.reflect.InvocationTargetException
>     [junit] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     [junit] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     [junit] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     [junit] 	at java.lang.reflect.Method.invoke(Method.java:585)
>     [junit] 	at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
>     [junit] 	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
>     [junit] 	... 33 more
>     [junit] Caused by: java.lang.SecurityException: class "d1.persist.Event$$EnhancerByCGLIB$$55c8eae8_2"'s signer information does not match signer information of other classes in the same package
>     [junit] 	at java.lang.ClassLoader.checkCerts(ClassLoader.java:775)
>     [junit] 	at java.lang.ClassLoader.preDefineClass(ClassLoader.java:487)
>     [junit] 	at java.lang.ClassLoader.defineClass(ClassLoader.java:614)
>     [junit] 	... 39 more
> No doubt there is some way to configure hibernate to create proxies in a different package, and I shall seek that option out. All I want to note here is that NPEs are not the best way to report failure. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list