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 9C2519763 for ; Thu, 14 Jun 2012 17:58:42 +0000 (UTC) Received: (qmail 11717 invoked by uid 500); 14 Jun 2012 17:58:42 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 11532 invoked by uid 500); 14 Jun 2012 17:58:42 -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 11523 invoked by uid 99); 14 Jun 2012 17:58:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jun 2012 17:58:41 +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 (athena.apache.org: domain of garydgregory@gmail.com designates 209.85.210.43 as permitted sender) Received: from [209.85.210.43] (HELO mail-pz0-f43.google.com) (209.85.210.43) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jun 2012 17:58:37 +0000 Received: by dajz8 with SMTP id z8so3324890daj.30 for ; Thu, 14 Jun 2012 10:58:17 -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=MDG1O0wUenbiiQxm1CJGcMTzRAfQerKMNOPCGCm7ZwM=; b=YH0ZX4UiYsWdc9z3dv2/slIE8EpB/v3WPr/tHKz/0HqnIU6BK1NNlomFlXYzhbc5uH jxQx0cNySGWKetZnC2ePq0D4rdZHbE9MkquqAYVgrfQFhDj6PL/9jpbmHyZ+GMbSRRex 9euz5Lrf25Y2beMDbgX2qveHumMA0I+af4AaXgkcVigyeqK0JCTeYFFnMajVZNGTgSAT NNcSvW7k2ZdDh+JikDhu+XnRQQiR4LovvPVwr5xG2WL9tLvnPZYSDx9UYw5H9iT4cSzI 9P0enPm98hDTbrkaKv4s8JU5v8nCSYPk/DRaLBRqCTwwHxo7a/wqZX9S/6DTmSzn3W4N 8weQ== MIME-Version: 1.0 Received: by 10.68.228.102 with SMTP id sh6mr9282148pbc.134.1339696696773; Thu, 14 Jun 2012 10:58:16 -0700 (PDT) Received: by 10.68.24.71 with HTTP; Thu, 14 Jun 2012 10:58:16 -0700 (PDT) In-Reply-To: References: <5755478650215755753@unknownmsgid> Date: Thu, 14 Jun 2012 13:58:16 -0400 Message-ID: Subject: Re: [VFS] ClassLoader pickle with OSGi (ClassCastException) From: Gary Gregory To: Commons Developers List Content-Type: multipart/alternative; boundary=e89a8ff2447bb7cd6b04c27271a9 X-Virus-Checked: Checked by ClamAV on apache.org --e89a8ff2447bb7cd6b04c27271a9 Content-Type: text/plain; charset=UTF-8 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 --e89a8ff2447bb7cd6b04c27271a9--