Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C76DA9937 for ; Thu, 14 Jun 2012 19:02:37 +0000 (UTC) Received: (qmail 94291 invoked by uid 500); 14 Jun 2012 19:02:37 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 94171 invoked by uid 500); 14 Jun 2012 19:02:37 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 94163 invoked by uid 99); 14 Jun 2012 19:02:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jun 2012 19:02:37 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of garydgregory@gmail.com designates 209.85.160.43 as permitted sender) Received: from [209.85.160.43] (HELO mail-pb0-f43.google.com) (209.85.160.43) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jun 2012 19:02:30 +0000 Received: by mail-pb0-f43.google.com with SMTP id wz7so4983365pbc.30 for ; Thu, 14 Jun 2012 12:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ASqDZkr+7rshr6i8cDgecDiXt9KtMq4QbUJKAPQ6RT8=; b=zQESeylm6Crq/Xyya+ggJIuuaUOS38UH9LdlER4NO+FTQQAr9vJ00I6ieaH0BTWprN EORg4tBpqJrUe51ivw/IBFHKVs8DubP2zNWxBg+PEadI7Ckm1kqlXnhSYAdmJSXP/9sp dAicUpW3K0zxBcQaSX92u3N6q2bZ/AxAsGPei/RwsNdgifaGkJrPwBBXIhRU4sE4xa8H t3mZ+Q9ryhrvP0MTBqu9cUenilmBZWmEvLEi2IsBsRvXxNCw37VleYeGEA0FxLVBkzaS lrY80Gpl5WhkUtHJ69TIYKvc4qE2zxrOPoIJjBXRq+5S2OmWngmzLjGQfSTwdBAhuonO hiGw== MIME-Version: 1.0 Received: by 10.68.233.193 with SMTP id ty1mr11297866pbc.47.1339700529387; Thu, 14 Jun 2012 12:02:09 -0700 (PDT) Received: by 10.68.24.71 with HTTP; Thu, 14 Jun 2012 12:02:09 -0700 (PDT) In-Reply-To: References: <5755478650215755753@unknownmsgid> Date: Thu, 14 Jun 2012 15:02:09 -0400 Message-ID: Subject: Re: [VFS] ClassLoader pickle with OSGi (ClassCastException) From: Gary Gregory To: Commons Developers List Content-Type: multipart/alternative; boundary=047d7b33d8d028d6ee04c27356a6 --047d7b33d8d028d6ee04c27356a6 Content-Type: text/plain; charset=UTF-8 On Thu, Jun 14, 2012 at 3:01 PM, Gary Gregory wrote: > On Thu, Jun 14, 2012 at 2:00 PM, James Carman wrote: > >> Are you using dynamic imports? >> > > No, VFS is on the Bundle-ClassPath. > And VFS and other jars in is our app server jar. Gary > Gary > >> >> On Thu, Jun 14, 2012 at 1:58 PM, Gary Gregory > >wrote: >> >> > On Thu, Jun 14, 2012 at 1:03 PM, Dan Tran wrote: >> > >> > > Thanks for discover this issue. Look likes FileProvider get excluded >> > > from export list? >> > > >> > >> > I do not think so, the 2.0 MANIFEST.MF includes: >> > >> > Export-Package: org.apache.commons.vfs2.impl;version="2.0",org.apache. >> > commons.vfs2.provider.url;version="2.0",org.apache.commons.vfs2.provi >> > ... >> > >> > The class is found and instantiated, but it cannot be cast because it >> comes >> > from a different class loader. >> > >> > Gary >> > >> > >> > > >> > > -D >> > > >> > > On Thu, Jun 14, 2012 at 4:53 AM, Gary Gregory > > >> > > wrote: >> > > > The classLoader ivar is initialized differently in 1.0 than in 2.0. >> > > > That's why the CCE shows up. A different class loader is used. I'm >> not >> > > > sure if there is a bug in 2.0 that was introduced when the >> classLoader >> > > > use was changed. I'm starting to think this was an unexpected side >> > > > effect. >> > > > >> > > > Gary >> > > > >> > > > On Jun 14, 2012, at 2:08, Ralph Goers >> > > wrote: >> > > > >> > > >> I have no idea why it worked in 1.0 and fails now. As far as I can >> > tell >> > > the call to createManager has always been there. I have no idea why. >> > > >> >> > > >> But I also don't know why >> > > >> >> > > >>> Caused by: java.lang.ClassCastException: >> > > >>> org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider >> > cannot >> > > be >> > > >>> cast to org.apache.commons.vfs2.provider.FileProvider >> > > >> >> > > >> is happening. That should be valid. >> > > >> >> > > >> >> > > >> Ralph >> > > >> >> > > >> On Jun 13, 2012, at 2:16 PM, Gary Gregory wrote: >> > > >> >> > > >>> Hi All: >> > > >>> >> > > >>> When I run under our OSGi (Eclipse Equinox) set up with 2.0, I get >> > this >> > > >>> pickle: >> > > >>> >> > > >>> org.apache.commons.vfs2.FileSystemException: Could not create a >> file >> > > system >> > > >>> manager of class >> > > "org.apache.commons.vfs2.impl.StandardFileSystemManager". >> > > >>> at org.apache.commons.vfs2.VFS.createManager(VFS.java:99) >> > > >>> at org.apache.commons.vfs2.VFS.getManager(VFS.java:50) >> > > >>> at >> > > >>> >> > > >> > >> com.seagullsw.toolbox.config.ConfigurationDirectory.resolveFileObject(ConfigurationDirectory.java:315) >> > > >>> at >> > > >>> >> > > >> > >> com.seagullsw.toolbox.config.Configuration.resolveFileObject(Configuration.java:135) >> > > >>> >> > > >>> at >> > > >>> >> > > >> > >> com.seagullsw.appinterface.server.osgi.JCicsOsgiTestCase.testJcicsOsgiRoundtrip(JCicsOsgiTestCase.java:226) >> > > >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > > >>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >> > > >>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >> Source) >> > > >>> at java.lang.reflect.Method.invoke(Unknown Source) >> > > >>> at >> org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:307) >> > > >>> at >> > > org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86) >> > > >>> at >> > > >>> >> > > >> > >> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:112) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:73) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282) >> > > >>> at >> > > org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84) >> > > >>> at >> > org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120) >> > > >>> at >> > > >>> >> > > >> > >> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34) >> > > >>> at >> > > >>> >> > > >> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:118) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:102) >> > > >>> at >> > > >>> >> > > >> > >> org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53) >> > > >>> at >> > > >>> >> > > >> > >> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) >> > > >>> at >> > > >>> >> > > >> > >> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) >> > > >>> at >> > > >>> >> > > >> > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) >> > > >>> at >> > > >>> >> > > >> > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) >> > > >>> at >> > > >>> >> > > >> > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) >> > > >>> at >> > > >>> >> > > >> > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) >> > > >>> Caused by: org.apache.commons.vfs2.FileSystemException: Could not >> > load >> > > VFS >> > > >>> configuration from >> > > >>> >> > > >> > >> "bundleresource://7.fwk545215872:34/org/apache/commons/vfs2/impl/providers.xml". >> > > >>> at >> > > >>> >> > > >> > >> org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:199) >> > > >>> at >> > > >>> >> > > >> > >> org.apache.commons.vfs2.impl.StandardFileSystemManager.init(StandardFileSystemManager.java:123) >> > > >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > > >>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >> > > >>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >> Source) >> > > >>> at java.lang.reflect.Method.invoke(Unknown Source) >> > > >>> at org.apache.commons.vfs2.VFS.createManager(VFS.java:88) >> > > >>> ... 49 more >> > > >>> Caused by: java.lang.ClassCastException: >> > > >>> org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider >> > cannot >> > > be >> > > >>> cast to org.apache.commons.vfs2.provider.FileProvider >> > > >>> at >> > > >>> >> > > >> > >> org.apache.commons.vfs2.impl.StandardFileSystemManager.addProvider(StandardFileSystemManager.java:371) >> > > >>> at >> > > >>> >> > > >> > >> org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:270) >> > > >>> at >> > > >>> >> > > >> > >> org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:195) >> > > >>> ... 55 more >> > > >>> >> > > >>> Which I work around with: >> > > >>> >> > > >>> private void initVfs() { >> > > >>> StandardFileSystemManager fsm = new >> > StandardFileSystemManager(); >> > > >>> fsm.setClassLoader(fsm.getClass().getClassLoader()); >> > > >>> try { >> > > >>> FieldUtils.writeDeclaredStaticField(VFS.class, >> "instance", >> > > fsm, >> > > >>> true); >> > > >>> fsm.init(); >> > > >>> } catch (FileSystemException e) { >> > > >>> ... >> > > >>> } catch (IllegalAccessException e) { >> > > >>> ... >> > > >>> } >> > > >>> } >> > > >>> >> > > >>> Two questions: >> > > >>> >> > > >>> (1) Why is org.apache.commons.vfs2.VFS.getManager() coded with a >> > class >> > > name >> > > >>> ref instead of the a real Class object or an actual instance: >> > > >>> >> > > >>> public static synchronized FileSystemManager getManager() >> > > >>> throws FileSystemException >> > > >>> { >> > > >>> if (instance == null) >> > > >>> { >> > > >>> instance = >> > > >>> >> > > >> createManager("org.apache.commons.vfs2.impl.StandardFileSystemManager"); >> > > >>> } >> > > >>> return instance; >> > > >>> } >> > > >>> >> > > >>> Why not: >> > > >>> >> > > >>> public static synchronized FileSystemManager getManager() >> > > >>> throws FileSystemException >> > > >>> { >> > > >>> if (instance == null) >> > > >>> { >> > > >>> instance = new StandardFileSystemManager(); >> > > >>> // where the StandardFileSystemManager constructor calls >> > > init(); >> > > >>> } >> > > >>> return instance; >> > > >>> } >> > > >>> >> > > >>> If not, what about adding a setManager(FileSystemManager)? >> > > >>> >> > > >>> This did not happen in 1.0, it worked fine in OSGi. >> > > >>> >> > > >>> Thank you, >> > > >>> Gary >> > > >>> >> > > >>> -- >> > > >>> E-Mail: garydgregory@gmail.com | ggregory@apache.org >> > > >>> JUnit in Action, 2nd Ed: >> http://bit.ly/ECvg0 >> > > >>> Spring Batch in Action: >> > http://bit.ly/bqpbCK >> > > >>> Blog: http://garygregory.wordpress.com >> > > >>> Home: http://garygregory.com/ >> > > >>> Tweet! http://twitter.com/GaryGregory >> > > >> >> > > >> >> > > >> >> --------------------------------------------------------------------- >> > > >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> > > >> For additional commands, e-mail: dev-help@commons.apache.org >> > > >> >> > > > >> > > > >> --------------------------------------------------------------------- >> > > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> > > > For additional commands, e-mail: dev-help@commons.apache.org >> > > > >> > > >> > > --------------------------------------------------------------------- >> > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> > > For additional commands, e-mail: dev-help@commons.apache.org >> > > >> > > >> > >> > >> > -- >> > E-Mail: garydgregory@gmail.com | ggregory@apache.org >> > JUnit in Action, 2nd Ed: http://bit.ly/ECvg0 >> > Spring Batch in Action: http://bit.ly/bqpbCK >> > Blog: http://garygregory.wordpress.com >> > Home: http://garygregory.com/ >> > Tweet! http://twitter.com/GaryGregory >> > >> > > > > -- > E-Mail: garydgregory@gmail.com | ggregory@apache.org > JUnit in Action, 2nd Ed: http://bit.ly/ECvg0 > Spring Batch in Action: http://bit.ly/bqpbCK > > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory > -- E-Mail: garydgregory@gmail.com | ggregory@apache.org JUnit in Action, 2nd Ed: http://bit.ly/ECvg0 Spring Batch in Action: http://bit.ly/bqpbCK Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory --047d7b33d8d028d6ee04c27356a6--