# HG changeset patch # User Vladimir Kvashin # Date 1326469532 -10800 # Branch release701_fixes # Node ID 785252283e6d2764124c863e53d3bac67f15eb6a # Parent 0839e938fc000a791b51630522b878d393d5930a fixed #207116 - NPE when deleting a directory in remote browser diff -r 0839e938fc00 -r 785252283e6d dlight.remote/src/org/netbeans/modules/remote/api/ui/FileObjectBasedFile.java --- a/dlight.remote/src/org/netbeans/modules/remote/api/ui/FileObjectBasedFile.java Wed Dec 14 18:13:39 2011 +0400 +++ b/dlight.remote/src/org/netbeans/modules/remote/api/ui/FileObjectBasedFile.java Fri Jan 13 18:45:32 2012 +0300 @@ -47,6 +47,9 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -60,7 +63,9 @@ import org.netbeans.modules.remote.spi.FileSystemProvider; import org.netbeans.modules.remote.support.RemoteLogger; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; import org.openide.util.RequestProcessor; import org.openide.util.Utilities; @@ -220,6 +225,42 @@ } @Override + public boolean delete() { + if (fo == null) { + fo = FileSystemProvider.getFileObject(env, path); + } + if (fo != null) { + try { + fo.delete(); + return true; + } catch (IOException ex) { + return false; + } + } + return false; + } + + @Override + public URI toURI() { + if (fo != null) { + // this will make need FileUtil.toFileObject return correct file object + StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); + if (stackTrace.length >= 3 && stackTrace[2].getClassName().equals(FileUtil.class.getName()) && stackTrace[2].getMethodName().equals("toFileObject")) { + try { + URL url = fo.getURL(); + URI uri = url.toURI(); + return uri; + } catch (FileStateInvalidException ex) { + Exceptions.printStackTrace(ex); + } catch (URISyntaxException ex) { + Exceptions.printStackTrace(ex); + } + } + } + return super.toURI(); + } + + @Override public boolean createNewFile() throws IOException { return super.createNewFile(); }