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 156549 - Race condition in Fix Imports
Summary: Race condition in Fix Imports
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P4 blocker (vote)
Assignee: Jan Lahoda
URL:
Keywords: RANDOM
Depends on:
Blocks:
 
Reported: 2009-01-09 23:19 UTC by _ gtzabari
Modified: 2009-11-02 10:59 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 _ gtzabari 2009-01-09 23:19:30 UTC
This issue is random. I get it around 25% of the time. This bug has been around for a long time (years probably), I just
never got around to reporting it. The data loss caused by this bug is rather minor so I leave it up to you to decide
whether this is a P2 or P3 issue.

Do the following to reproduce the bug:

1) Open a Java file with at least 1000 lines of code (the key is to make sure parsing takes a while) with some of its
imports missing.
2) Issue "Fix Imports" and click OK
3) Before the parser has time to re-parse the file, hit "Fix Imports" again.
4) At this point you will receive the same imports against or (worse yet) some previously resolved imports will now show
up as missing and need to be resolved again.
5) Once you fill out the form and hit OK you will fix the import section is corrupt with contents like this:

------------------------
import javax.imageio.stream.FileCacheImageOutputStream;
import javax.imageio.stream.ImageInputStream;
import nu.xom.Document;

import java.awt.image

 .BufferedImage;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStreByteArrayOutputStream;

import java.io.IOExceptiIOException;

import java.io.InInputStream;

import java.net.UURI;

import java.util.ArrayList;

import java.util.Collection;
import java.util.CollectiCollections;
import java.util.Iterator;
import javax.imageio.ImageIO;
imimport javax.

imageio.ImageReader;
imimport javax.

 imageio.ImageWriter;

import javax.imageio.strstream.FileCacheImageOutputStream;

import javax.iimageio.stream.ImageInputStream;
impimport javax.

 ws.rs.core

 .MeMediaType;

import nu.xom.BBuilder;

import nu.xom.DDocument;
------------------------

It looks like two race conditions are going on:

1) "Fix Imports" operates on an out-of-date view of the file
2) It looks like two processes are writing into the file at the same time which is why you end up with lines like this:

imimport javax.

imageio.ImageReader;
imimport javax.

 imageio.ImageWriter;
Comment 1 Peter Pis 2009-01-10 23:32:02 UTC
Reassigning to editor.
Comment 2 Vitezslav Stejskal 2009-01-15 11:25:48 UTC
Thanks for the report. I tried to reproduce it in a dev build, but without success.

Product Version: NetBeans IDE Dev (Build 090115)
Java: 1.5.0_14; Java HotSpot(TM) Client VM 1.5.0_14-b03
System: Linux version 2.6.22-16-generic running on i386; UTF-8; en_US (nb)
Userdir: /home/vita/devel/netbeans/main/nbbuild/testuserdir
Comment 3 _ gtzabari 2009-01-15 15:35:08 UTC
I'm curious, did you inspect the code for any sort of synchronization between:

1) Exporting new imports when the Fix Imports dialog is closed, and
2) Scanning existing imports before the Fix Imports dialog comes up

Random issues will definitely be hard to reproduce but if the code has no synchronization to begin with then we can fix
the problem without fully reproducing it.
Comment 4 Jan Lahoda 2009-02-02 10:48:35 UTC
I think this can happen. OTOH, the solution is simple: do not invoke the Fix All Imports action twice so quickly (I do
not see the usecase for this anyway). So, fixing this does not seem like a big priority to me - there seem to be more
urgent problems to fix. However, feel free to provide a patch.
Comment 5 _ gtzabari 2009-02-02 23:48:37 UTC
Users need to invoke Fix Imports multiple times quickly because sometimes the first invocation does not resolve all the
missing imports. For example, if you have an anonymous class then the first invocation of Fix Imports will resolve
classes outside the class, the second invocation will resolve inside the class. At least, that's been my experience.
Comment 6 Quality Engineering 2009-11-02 10:59:18 UTC
NetBeans.org Migration: changing resolution from LATER to WONTFIX