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 88424 - CopyPaste class corrupts package statement
Summary: CopyPaste class corrupts package statement
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All Windows XP
: P1 blocker with 1 vote (vote)
Assignee: Pavel Flaska
URL:
Keywords:
: 89209 90835 92132 92775 96337 99922 101932 (view as bug list)
Depends on:
Blocks: 99509 99900
  Show dependency tree
 
Reported: 2006-11-01 15:21 UTC by Jiri Prox
Modified: 2007-04-23 10:31 UTC (History)
7 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Hack for fixing problem - not applicable! (914 bytes, application/octet-stream)
2006-11-06 15:38 UTC, Pavel Flaska
Details
Another bad solution (2.00 KB, application/octet-stream)
2007-04-10 15:22 UTC, Pavel Flaska
Details
Corrupted Java file for web service created from WSDL (903 bytes, text/plain)
2007-04-11 18:04 UTC, Roderico Cruz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Prox 2006-11-01 15:21:09 UTC
NetBeans IDE Dev (Build 061101)
1.6.0-rc; Java HotSpot(TM) Client VM 1.6.0-rc-b100
Windows XP version 5.1 running on x86
en_US (nb); Cp1252

Copy&Pasting class t odifferent package corrupts package statement.

Steps to reproduce:
1) have an empty class in  org.netbeans.test.java.gui.copypaste.test package
2) create package org.netbeans.test.java.gui.copypaste.test2
3) copy & paste (in the project view) the class to the new package
->
/*
 * TestClass.java
 *
 */

pacorg.netbeans.test.java.gui.copypaste.test2.test;

/**
 *
 */
public class TestClass {
    
    /** Creates a new instance of TestClass */
    public TestClass() {
    }
    
}
Comment 1 Pavel Flaska 2006-11-06 10:16:53 UTC
I'm not able to reproduce it, maybe it is a platform specific for windows. The
number of new lines are 5, missing characters are also 5 - "kage ". Seems like
there are \r characters which were not used in position computing.
Comment 2 Pavel Flaska 2006-11-06 12:15:30 UTC
Description how to reproduce steps:

i) use source text with cr/lf sequence before the package statement,
ii) position for package name is moved - the shift is number of cr chars.
Comment 3 Pavel Flaska 2006-11-06 15:38:15 UTC
Created attachment 35801 [details]
Hack for fixing problem - not applicable!
Comment 4 Pavel Flaska 2006-11-08 16:27:35 UTC
By the way, this is a more general issue - when reading source
SourceFileObject.getCharContentImpl() - all \r characters are filtered out. This
means that position are resolved for the source without \r, i.e. offsets are
correct when document for file exists. Then, when write operation is used and
ModificationResult class takes down the changes to file, positions are
incorrect. Bear in mind this is only in cases \r characters are in the file.
(All works as expected if document exists, then ModificationResult writes down
changes to document instead of file.)

Comment 5 Pavel Flaska 2006-11-08 16:39:59 UTC
Possible solutions:
i) apply "not applicable" hack - for not opened files document will be created.
This will have negative impact to performance, that is the reason why it is
marked as "not applicable".

ii) encapsulate offsets to class - Such a class will provide correct offsets for
closed/opened files. This means huge number of changes, direct offset handling
has to be forbidden.

iii) when document is created for file, notify users that position obtained
before are no longer valid. It is breakneck solution, but currently just
refactoring are client which uses positions from file which has to be converted
to new position. (Consider click to usage in the file which is not opened - file
is opened and correct selection has to be done in editor.)

Comment 6 Jiri Prox 2006-11-13 15:17:44 UTC
*** Issue 89209 has been marked as a duplicate of this issue. ***
Comment 7 Pavel Flaska 2007-01-08 18:21:51 UTC
In case we have to fix it in 6.0, I suggest to apply "not applicable" fix. This
will have negative performance impact.
Comment 8 _ tboudreau 2007-01-09 17:48:31 UTC
FYI, I see this problem constantly - copying a class makes complete hamburger
out of the head of the file - all the imports part of the opening comment, the
package statement gets characters from the class name mixed into it - you get an
uncompilable mess.  I was figuring it was probably a CRLF-related problem.

Swing Swing documents exclusively use \n as the line terminator, you could avoid
creating the Document, but preprocess the document text, e.g.

String lt = (String) System.getProperty ("line.separator");
if (lt.length() > 1) {
   documentContent = documentContent.replace (lt, "\n");
}
and if necessary, replace "\n" with lt again before writing out the result.  I
had to do something like this to do error hints for included XML files in the
DocBook module.  

It's still extra work, but less work than creating a Document for the file.
Comment 9 Pavel Flaska 2007-01-10 09:32:12 UTC
Yes. This seems to be the best solution. Just one question:
Consider sources checked out with \r\n on Windows. File will change and all its
\r\n will be converted to \n. When file is check in, is just the 'real' change
visible (though no changes in end lines are registered? -- When file is check
out again, are there again \r\n?
Comment 10 Pavel Flaska 2007-01-10 09:52:42 UTC
*** Issue 92132 has been marked as a duplicate of this issue. ***
Comment 11 davidev 2007-01-17 08:56:00 UTC
This is a big issue for windows users.
I wish to test the new 6.0 features, but all the copied java class result
corrupted, and this makes the IDE impossible to use.
please fix it.
thanks
Comment 12 Pavel Flaska 2007-01-17 09:00:42 UTC
We know we have to fix it. But this need some consensus how to do that, we still
do not have good solution for it. For the time being, use the hack attached,
which can temporarily help.
Comment 13 Pavel Flaska 2007-01-18 14:30:13 UTC
*** Issue 92775 has been marked as a duplicate of this issue. ***
Comment 14 Lukas Hasik 2007-01-19 07:56:02 UTC
It's really annoying issue. I don't want to see it fixed somewhere in "future".
IMO, there is plenty of time to fix it in 6.0 
Comment 15 Pavel Flaska 2007-01-19 09:05:10 UTC
Of course, it has to be fixed in 6.0. You are a hair-splitter. :-)
Comment 16 Pavel Flaska 2007-02-14 11:42:16 UTC
*** Issue 90835 has been marked as a duplicate of this issue. ***
Comment 17 Pavel Flaska 2007-03-19 11:36:03 UTC
*** Issue 96337 has been marked as a duplicate of this issue. ***
Comment 18 Pavel Flaska 2007-04-04 12:33:05 UTC
*** Issue 99900 has been marked as a duplicate of this issue. ***
Comment 19 Pavel Flaska 2007-04-05 12:53:12 UTC
*** Issue 99922 has been marked as a duplicate of this issue. ***
Comment 20 Pavel Flaska 2007-04-10 15:22:04 UTC
Created attachment 40685 [details]
Another bad solution
Comment 21 Pavel Flaska 2007-04-10 15:26:07 UTC
Previously added attachment removes all \r characters from input stream during
writing output. It should eliminate problems reported here, unfortunately there
will be just \n characters. -- During writing, I can change it back to \r\n.
Both things can have negative perf impact, especially the second one. (not
implemented yet.)
Comment 22 Roderico Cruz 2007-04-11 17:45:02 UTC
Our generation for web services also experiences this problem. See attached. Our
use case is: 1) create an empty class from a template. 2) generate new methods
and annotations to it.
Comment 23 Roderico Cruz 2007-04-11 18:04:53 UTC
Created attachment 40759 [details]
Corrupted Java file for web service created from WSDL
Comment 24 Pavel Flaska 2007-04-12 09:41:33 UTC
After the discussion with other team members, we finally decided to reparse the
source when opened to editor. -- There will be no need to preprocess \r
characters when reading files and offset positions will be correct. Hopefully
nobody holds the offset positions outside the task.
Comment 25 Tomas Zezula 2007-04-12 12:16:42 UTC
Checking in src/org/netbeans/api/java/source/JavaSource.java;
/cvs/java/source/src/org/netbeans/api/java/source/JavaSource.java,v  <-- 
JavaSource.java
new revision: 1.37; previous revision: 1.36
done
Checking in src/org/netbeans/modules/java/source/parsing/SourceFileObject.java;
/cvs/java/source/src/org/netbeans/modules/java/source/parsing/SourceFileObject.java,v
 <--  SourceFileObject.java
new revision: 1.7; previous revision: 1.6
done
Checking in test/unit/src/org/netbeans/api/java/source/JavaSourceTest.java;
/cvs/java/source/test/unit/src/org/netbeans/api/java/source/JavaSourceTest.java,v
 <--  JavaSourceTest.java
new revision: 1.9; previous revision: 1.8
done
Comment 26 Pavel Flaska 2007-04-12 16:13:57 UTC
v.
Comment 27 Jiri Prox 2007-04-23 10:31:50 UTC
*** Issue 101932 has been marked as a duplicate of this issue. ***