This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 60475 - NPE while updating form files programmatically
Summary: NPE while updating form files programmatically
Status: CLOSED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 4.x
Hardware: All All
: P1 blocker (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-24 08:32 UTC by Ayub Khan
Modified: 2006-03-24 12:56 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ayub Khan 2005-06-24 08:32:39 UTC
I have an application that tries to update form file programmatically, as follows

	FileObject[] fileObjects=(FileObject[])dataObject.files().toArray(new
FileObject[0]);
	for(int i=0;i<fileObjects.length;i++)
	{
		FileObject fileObject=fileObjects[i];
		String fileContent=<Latest file contents>
		try 
		{
			FileSystem fs = fileObject.getFilesystem();
			fs.runAtomicAction(new FileSystem.AtomicAction() 
			{
				public void run() throws IOException 
				{					
					ByteArrayInputStream inputStream=
						 new ByteArrayInputStream(fileContent);
					try 
					{					
						fileLock = fileObject.lock();
					}
					catch (FileAlreadyLockedException ale)
					{
						//ignore
					}
					fileOutputStream = fileObject.getOutputStream(fileLock);
					StreamCopier.copyStream(inputStream,fileOutputStream);						
				}
			}); 
		}
		catch(FileStateInvalidException ex) 
		{
			ErrorManager.getDefault().notify(ex);
		}		
		catch(IOException ex) 
		{
			ErrorManager.getDefault().notify(ex);
		}				 
		catch(Exception ex) 
		{
			ErrorManager.getDefault().notify(ex);
		}
		finally 
		{
			if(fileLock!=null)
			{
				fileLock.releaseLock();
			}
			try
			{
				if(fileOutputStream!=null)
				{
					fileOutputStream.close();
				}
			}
			catch (IOException e)
			{
				e.printStactTrace();
			}
		}
		fileObject.refresh(false);
	}
		
After update, I get the following NPE. It looks like the form dataloader is trying
to invoke reload of form document, even though the document is not open.

When a form document is not opened, its MultiView components are null. This
exception
is related to this.

java.lang.NullPointerException
	at
org.netbeans.modules.form.FormEditorSupport.reloadDocument(FormEditorSupport.java:717)
	at
org.openide.text.CloneableEditorSupport.checkReload(CloneableEditorSupport.java:1744)
	at
org.openide.text.CloneableEditorSupport.access$1600(CloneableEditorSupport.java:79)
	at org.openide.text.CloneableEditorSupport$9.run(CloneableEditorSupport.java:2112)
	at org.netbeans.editor.BaseDocument.runAtomicAsUser(BaseDocument.java:1086)
	at org.netbeans.editor.GuardedDocument.runAtomic(GuardedDocument.java:217)
	at org.openide.text.NbDocument.runAtomic(NbDocument.java:341)
[catch] at
org.openide.text.CloneableEditorSupport$9.run(CloneableEditorSupport.java:2108)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
	at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
	at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Comment 1 Ayub Khan 2005-08-10 17:30:02 UTC
This is a showstopper bug for Java Studio Enterprise 8 Release.
Comment 2 Jan Stola 2005-08-10 17:40:53 UTC
I am sorry I am not able to reproduce the issue. Please, describe
steps to reproduce. If the issue cannot be reproduced using normal
user gestures then attach a test case.
Comment 3 pgebauer 2005-08-10 21:50:55 UTC
A testcase was sent to jstola
Comment 4 Tomas Pavek 2005-08-11 15:10:34 UTC
I've made a very simple fix trying to avoid the exception. It is in trunk,
please test.

/cvs/form/src/org/netbeans/modules/form/FormEditorSupport.java,v  <-- 
FormEditorSupport.java
new revision: 1.173; previous revision: 1.172

http://form.netbeans.org/source/browse/form/src/org/netbeans/modules/form/FormEditorSupport.java?r1=1.172&r2=1.173
Comment 5 pgebauer 2005-08-11 21:20:18 UTC
The fix works. Thanks.

Backported into release41_fixes.
Checking in form/src/org/netbeans/modules/form/FormEditorSupport.java;
/cvs/form/src/org/netbeans/modules/form/FormEditorSupport.java,v  <-- 
FormEditorSupport.java
new revision: 1.171.16.1; previous revision: 1.171
Comment 6 Marek Grummich 2006-01-19 10:41:23 UTC
Verified