[
https://issues.apache.org/jira/browse/VFS-683?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16696193#comment-16696193
]
Otto Fowler commented on VFS-683:
---------------------------------
For example -> your code works, with the following modifications:
{code:java}
package org.apache.ottobackwards;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileType;
import org.apache.commons.vfs2.FileUtil;
//import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
import org.apache.commons.vfs2.impl.StandardFileSystemManager;
import org.apache.commons.vfs2.provider.tar.TarFileProvider;
public class Main {
/**
* The first parameter (args[0]) should be an directory within an archive
file. For example:
* tgz:file://Users/daryl/zookeeper-3.4.13.tgz!zookeeper-3.4.13/docs
*/
public static void main(String[] args) {
try {
System.out.println("File selected is " + args[0]);
Thread[] threads = new Thread[2];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(new FileObjectReadingThread(args[0]),
String.format("THREAD--(%d)-->",i));
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join(0);
}
} catch (Exception ex) {
System.out.println("Main caught " + ex.getClass().getName() + ": " +
ex.getMessage());
ex.printStackTrace(System.out);
}
}
static class FileObjectReadingThread implements Runnable {
String filePath;
FileObjectReadingThread(String pathname) {
filePath = pathname;
}
@Override
public void run() {
try {
FileSystemManager fileSystemManager = createFileSystemManager();
FileObject fileObject = fileSystemManager.resolveFile(filePath);
System.out.println("Thread " + Thread.currentThread().getName() + " " +
this + " running with FileObject " + System.identityHashCode(fileObject));
FileObject[] children = fileObject.getChildren();
for (FileObject child : children) {
if (child.getType() == FileType.FILE && child.isReadable()) {
System.out.println("Thread " + Thread.currentThread().getName() + "
" + this + " is reading " + child);
FileUtil.getContent(child);
}
Thread.sleep(1); // force a yield to other threads
}
} catch (Exception ex) {
System.out.println("Thread " + Thread.currentThread().getName() + " " +
this + " caught " + ex.getClass().getName() + ": " + ex.getMessage());
ex.printStackTrace(System.out);
}
}
private FileSystemManager createFileSystemManager() throws Exception {
DefaultFileSystemManager fileSystemManager = new
StandardFileSystemManager();
fileSystemManager.init();
return fileSystemManager;
}
}
}
{code}
> Thread safety issue in VFSClassLoader - NullPointerException thrown
> -------------------------------------------------------------------
>
> Key: VFS-683
> URL: https://issues.apache.org/jira/browse/VFS-683
> Project: Commons VFS
> Issue Type: Bug
> Affects Versions: 2.2
> Reporter: Daryl Odnert
> Priority: Major
> Attachments: Main.java
>
>
> In my application, I have two instances of the {{VFSClassLoader}}, each of
> which is being used in a distinct thread. Both {{VFSClassLoader}} instances
> refer to the same compressed file resource described by a {{FileObject}} that
> is passed to the class loader's constructor. Intermittently, the application
> throws an exception with the stack trace shown below. So, there seems to be
> either a race condition in the code or an undocumented assumption here. If it
> is unsupported for two {{VFSClassLoader}} instances to refer to the same
> resource (file), then that assumption should be documented. But if that is
> not the case, then there is a race condition bug in the implementation.
> {noformat}
> 43789 WARN {} c.a.e.u.PreferredPathClassLoader - While loading class
> org.apache.hive.jdbc.HiveDatabaseMetaData, rethrowing unexpected
> java.lang.NullPointerException: Inflater has been closed
> java.lang.NullPointerException: Inflater has been closed
> at java.util.zip.Inflater.ensureOpen(Inflater.java:389)
> at java.util.zip.Inflater.inflate(Inflater.java:257)
> at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:152)
> at java.io.BufferedInputStream.read1(BufferedInputStream.java:284)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
> at
> org.apache.commons.vfs2.util.MonitorInputStream.read(MonitorInputStream.java:91)
> at org.apache.commons.vfs2.FileUtil.getContent(FileUtil.java:47)
> at org.apache.commons.vfs2.impl.Resource.getBytes(Resource.java:102)
> at
> org.apache.commons.vfs2.impl.VFSClassLoader.defineClass(VFSClassLoader.java:179)
> at
> org.apache.commons.vfs2.impl.VFSClassLoader.findClass(VFSClassLoader.java:150)
> at
> com.atscale.engine.utils.PreferredPathClassLoader.findClass(PreferredPathClassLoader.scala:54)
> {noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)