1 19 20 package org.openide.loaders; 21 22 import org.openide.filesystems.*; 23 import org.openide.loaders.*; 24 import java.beans.*; 25 import java.io.IOException ; 26 import junit.textui.TestRunner; 27 import org.netbeans.junit.*; 28 29 32 public class NullPointer35897Test extends NbTestCase { 33 private FileSystem lfs; 34 private FileObject file; 35 private L loader; 36 private D obj; 37 38 public NullPointer35897Test (String name) { 39 super (name); 40 } 41 42 protected void setUp () throws Exception { 43 TestUtilHid.destroyLocalFileSystem (getName ()); 44 String fsstruct [] = new String [] { 45 "dir/simple.simple" 46 }; 47 lfs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct); 48 Repository.getDefault ().addFileSystem (lfs); 49 50 file = lfs.findResource (fsstruct[0]); 51 52 loader = (L)DataLoader.getLoader (L.class); 53 AddLoaderManuallyHid.addRemoveLoader (loader, true); 54 } 55 56 protected void tearDown () throws Exception { 58 AddLoaderManuallyHid.addRemoveLoader (loader, false); 59 TestUtilHid.destroyLocalFileSystem (getName ()); 60 } 61 62 public void test35897 () throws Exception { 63 class InitObj implements Runnable { 64 public void run () { 65 try { 66 obj = (D)DataObject.find (file); 67 } catch (DataObjectNotFoundException ex) { 68 ex.printStackTrace(); 69 fail ("Unexpected exception"); 70 } 71 } 72 } 73 InitObj init = new InitObj (); 74 75 org.openide.util.RequestProcessor.Task task; 76 synchronized (loader) { 77 task = org.openide.util.RequestProcessor.getDefault ().post (init); 78 loader.wait (); 79 } 80 81 assertTrue ("The creation of DataObject is blocked in constructor", loader.waitingInConstructor); 82 83 Repository.getDefault ().removeFileSystem (lfs); 84 85 synchronized (loader) { 86 loader.notifyAll (); 87 } 88 task.waitFinished (); 89 90 assertNotNull ("The object has been finished", obj); 91 } 92 93 private static class D extends MultiDataObject { 94 private boolean constructorFinished; 95 96 public D (FileObject pf, L loader) throws IOException { 97 super(pf, loader); 98 99 synchronized (loader) { 100 try { 101 loader.waitingInConstructor = true; 102 loader.notifyAll (); 103 loader.wait (2000); 104 } catch (InterruptedException ex) { 105 ex.printStackTrace(); 106 fail ("No interruptions please"); 107 } finally { 108 loader.waitingInConstructor = false; 109 constructorFinished = true; 110 } 111 } 112 } 113 114 115 116 protected org.openide.nodes.Node createNodeDelegate() { 117 return org.openide.nodes.Node.EMPTY; 118 } 119 120 public java.util.Set files () { 121 assertTrue ("This can be called only if the constructor is finished", constructorFinished); 122 return super.files (); 123 } 124 125 } 126 127 private static class L extends MultiFileLoader { 128 public boolean waitingInConstructor; 129 130 public L () { 131 super(D.class.getName()); 132 } 133 protected String displayName() { 134 return "L"; 135 } 136 137 protected FileObject findPrimaryFile (FileObject obj) { 138 return obj.hasExt ("simple") ? obj : null; 139 } 140 141 protected MultiDataObject createMultiObject(FileObject pf) throws IOException { 142 return new D(pf, this); 143 } 144 145 146 protected MultiDataObject.Entry createSecondaryEntry (MultiDataObject x, FileObject obj) { 147 throw new IllegalStateException (); 148 } 149 150 protected MultiDataObject.Entry createPrimaryEntry (MultiDataObject x, FileObject obj) { 151 return new org.openide.loaders.FileEntry (x, obj); 152 } 153 } 154 155 156 } 157 | Popular Tags |