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 89982 - NPE when using search&replace makes IDE unusable
Summary: NPE when using search&replace makes IDE unusable
Status: VERIFIED FIXED
Alias: None
Product: utilities
Classification: Unclassified
Component: Search (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Marian Petras
URL:
Keywords:
Depends on:
Blocks: 89637
  Show dependency tree
 
Reported: 2006-11-24 08:36 UTC by Max Sauer
Modified: 2006-11-24 19:27 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
NPE stack trace (1.66 KB, text/plain)
2006-11-24 10:45 UTC, Max Sauer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Max Sauer 2006-11-24 08:36:22 UTC
Using Search and replace makes IDE unusable -- following NPE is thrown almost
upon every action. The search output window has to be closed in order to stop
this. Reproducible almost every time.

java.lang.NullPointerException
	at javax.swing.JList$1.getSize(JList.java:425)
	at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1319)
	at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1288)
	at javax.swing.plaf.basic.BasicListUI.getPreferredSize(BasicListUI.java:560)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1627)
...
(whole stack trace attached)

Steps to reproduce:
-------------------
1) Start IDE with fresh userdir
2) Create a new j2se project
3) From project's Explorer context menu, invoke "Find"
4) Fill in "Main" for searched item, and "some" for replace item
5) Confirm dialog
=> NPE
6) Try to ie. view some window from Window menu
=> NPE

---
NetBeans IDE Dev (Build 061124)
1.6.0-rc; Java HotSpot(TM) Server VM 1.6.0-rc-b104
Linux version 2.6.12-1.1390_FC4smp running on i386
en_US (nb); UTF-8
Comment 1 Max Sauer 2006-11-24 09:14:08 UTC
This is a showstopper for M5.
Comment 2 Marian Mirilovic 2006-11-24 09:42:33 UTC
Max, 
please attach the whole stack trace, thanks in advance.
Comment 3 Max Sauer 2006-11-24 10:45:58 UTC
Created attachment 36263 [details]
NPE stack trace
Comment 4 Marian Petras 2006-11-24 10:58:17 UTC
There is always an exception preceding the already reported exception:

    java.lang.IllegalStateException: Buffer is gone
	at ...search.MatchingObject.write(MatchingObject.java:607)
	at ...search.ReplaceTask.doReplace(ReplaceTask.java:144)
	at ...search.ReplaceTask.replace(ReplaceTask.java:91)
	at ...search.ReplaceTask.run(ReplaceTask.java:77)

        ... (invoked form a RequestProcessor) ...
Comment 5 Marian Petras 2006-11-24 11:29:24 UTC
Fixed (in the trunk).

The cause of the bug was the following: When modifying the file's contents, the
file's content is always read from the file, even if it has already been read
before. In other words, the cached content is not used. But when writing the
content back to file, it is the cached content that is written. The bug was that
the special method for reading the file's content from the file (skipping the
cache) did not refresh (or fill) the cache (text buffer) which is then used when
writing. If the cache had not been filled earlier by some other operation, it
was empty (null) at the moment of writing the content back to the file.
   The fix is simple - change the method that forcibly reads the text from the
file always stores the read text to the cache.
   The reason why I did not catch this bug was that before performing the
'replace' operation, I apparently always made some other operation that filled
the cache (buffer). For example, previewing the file's content in the right
panel of the results window reads the file's content and saves it to the cache.

Modified file:
    utilities/src/org/netbeans/modules/search/MatchingObject.java   (1.2)

Diff:
http://utilities.netbeans.org/source/browse/utilities/src/org/netbeans/modules/search/MatchingObject.java?r1=1.1&r2=1.2&diff_format=u
Comment 6 Marian Petras 2006-11-24 15:17:13 UTC
Oops! The fix still contained a bug. Now fixed:

Modified file:
    utilities/src/org/netbeans/modules/search/MatchingObject.java   (1.3)

Diff:
http://utilities.netbeans.org/source/browse/utilities/src/org/netbeans/modules/search/MatchingObject.java?r1=1.2&r2=1.3&diff_format=u
Comment 7 Max Sauer 2006-11-24 19:27:19 UTC
Verified. Thanx for the quick fix, Marian..
---
NetBeans IDE Dev (Build 20061124-1716)
1.6.0-rc; Java HotSpot(TM) Client VM 1.6.0-rc-b104
Linux version 2.6.11.3 running on i386
cs_CZ (nb); ISO-8859-2