Hmmm, has to be a threading issue I think, ran your test on my infamous "H" drive and navigated the entire structure (large!) with no problems.
I'll go look at synchronising properly and see how I go. Thanks heaps for taking a look. cheers, Paul > -----Original Message----- > From: Mario Ivankovits [mailto:[EMAIL PROTECTED] > Sent: Friday, 21 May 2004 3:55 PM > To: Jakarta Commons Developers List > Subject: Re: [VFS]: NPE in FileObject.getType().getChildren() > > > Paul Smith wrote: > > >I am getting an NPE in the following line of code, and I > think it must be > >thread related or something. > > > I have tried to reproduce it, but wasnt able to. > > I collected your code into an test-class, not knowing if this > is really > what happens on your machine. > > vfs itself do not use threading, and in your case, if it cant > determine > the type (=null) is is used IMAGINARY by default and thus > cant be null.- > i wonder how your NPE can happen. > But vfs itself is not thread save, if you access the same fileobject > from two thread you should synchronize on them. > > ... > > Now i have found a way, how this could happen too. If vfs > cant determine > the type the fileobject is already in state "attached" but > the type is > null then. However, an exception should have been thrown. > Maybe your posted exception is only the aftereffect from another > exception before? > > Could you please have a look in this direction. > Also please try this code - and eventually complete it to make them > throw the exception. > > --Mario > > ---cut--- > /* > * Copyright 2002, 2003,2004 The Apache Software Foundation. > * > * Licensed 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.commons.vfs.example; > > import org.apache.commons.vfs.FileObject; > import org.apache.commons.vfs.FileSystemManager; > import org.apache.commons.vfs.VFS; > import org.apache.commons.vfs.FileSystemException; > > import java.io.File; > import java.util.ArrayList; > import java.util.Arrays; > import java.util.Collection; > import java.util.Iterator; > > public class VFSChainsaw > { > public static void main(String[] args) throws Exception > { > FileSystemManager fileSystemManager = VFS.getManager(); > > File[] roots = File.listRoots(); > for (int i = 0; i < roots.length; i++) > { > File root = roots[i]; > > /* uncomment to recurse only a specific driver > if > (!root.getAbsolutePath().toLowerCase().startsWith("x:")) > { > continue; > } > */ > > if > (!(root.getAbsolutePath().toLowerCase().startsWith("a:") || > > root.getAbsolutePath().toLowerCase().startsWith("b:"))) > { > if (root.exists() && root.canRead()) > { > FileObject fileObject = fileSystemManager > .resolveFile(root.toURL().toExternalForm()); > > System.err.println("local:" + > root.getAbsolutePath() > + " fo:" + fileObject); > > int count = recurse(fileObject); > System.err.println("Number Of files: "+ count); > } > } > } > } > > private static int recurse(FileObject fileObject) throws > FileSystemException > { > int count = 0; > > FileObject[] fos = fileObject.getChildren(); > Collection objects = new ArrayList(Arrays.asList(fos)); > for (Iterator iter = objects.iterator(); iter.hasNext();) > { > count++; > FileObject fo = (FileObject) iter.next(); > if (fo.getType().hasChildren()) > { > // System.err.println("child:" + fo); > iter.remove(); > > count+=recurse(fo); > } > } > > return count; > } > } > ---cut--- > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
