Bug 149028 - Limiting number of characters to read with the file size is invalid.
Summary: Limiting number of characters to read with the file size is invalid.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 major with 1 vote (vote)
Target Milestone: 3.2.1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 150745 151905 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-06-28 12:00 EDT by Egor Shchegolkov CLA
Modified: 2008-02-28 04:55 EST (History)
3 users (show)

See Also:


Attachments
Proposed fix and regression test (6.79 KB, patch)
2006-06-29 17:31 EDT, Jerome Lanneluc CLA
no flags Details | Diff
Improved fix (with same regression test) (7.79 KB, patch)
2006-07-04 09:09 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Egor Shchegolkov CLA 2006-06-28 12:00:26 EDT
The implemetation of org.eclipse.jdt.internal.core.util.getResourceContentsAsCharArray(IFile file, String encoding) now limits the number of characters to read with the size of file. This leads to weird syntax errors due to tail of the file is skipped when custom encoding that produces more than one character per byte is used.

To reproduce install Simple Java Preprocessor (http://www.vortoj.com/sjpp/readme.html) and create file
public class A
{
  public static void main( String[] args )
  {
#if ABC
#endif
  }
}
After setting proper encoding the errors 'Syntax error, insert '}' to complete ClassBody' and 'Syntax error, insert '}' to complete MethodBody' will occur.

This error was found in Eclipse 3.2RC7, version 3.1.2 reads file until EOF and all work fine.
Comment 1 Egor Shchegolkov CLA 2006-06-28 12:06:51 EDT
Sorry, the name of the class was missed. the proper name of the method is
org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(IFile file,
String encoding)
Comment 2 Philipe Mulet CLA 2006-06-28 12:08:51 EDT
Too bad only discovered now. Will queue it for 3.2.1.
Comment 3 Philipe Mulet CLA 2006-06-28 12:26:10 EDT
This is a consequence of a performance change, which caused this one scenario.
We will provide a fix which preserves the performance characteristics.

Wondering about 3.2.0 late escalating... 
Comment 4 Jerome Lanneluc CLA 2006-06-28 12:44:11 EDT
Note that the batch compiler always had this bug. The bug in the Java builder and other JDT tooling was also introduced with jdt.core v_645 during 3.2 M6.
Comment 5 Charles Doucette CLA 2006-06-28 14:17:00 EDT
Apparently, if you add newlines and/or spaces to the end of the file,
you can work-around this problem. At least that worked for one of my sample files
which had this problem (use of SJPP produced syntax errors at the end of the file).
Comment 6 Philipe Mulet CLA 2006-06-29 07:19:22 EDT
Re: 3.2.0 escalation
We had the same bug in batch compiler since ever, and no one ever complained.
Now we made it more proeminent by breaking the builder as well as the entire JDT stack. So though it is bad, it is not a show stopper, considering there is a workaround (adding extra space at end of the file), and no one discovered it in a long time (the offending change has been in for months).

Nevertheless, we will make a fix available for 3.2.1 and post a patch on our JDT/Core web page for early access to our 3.2.1 update (in progress).

Jerome - pls advertize in this bug where to get the early patch
Comment 7 Jerome Lanneluc CLA 2006-06-29 17:31:43 EDT
Created attachment 45560 [details]
Proposed fix and regression test
Comment 8 Jerome Lanneluc CLA 2006-07-04 09:09:25 EDT
Created attachment 45701 [details]
Improved fix (with same regression test)
Comment 9 Jerome Lanneluc CLA 2006-07-11 10:11:52 EDT
Patch and regression test released for 3.3 M1 in HEAD
Comment 10 Jerome Lanneluc CLA 2006-07-11 10:20:20 EDT
Patch and regression test released for 3.2.1 in R3_2_maintenance branch.
Comment 11 Jerome Lanneluc CLA 2006-07-11 10:30:30 EDT
A 3.2.1 preview (including the fix to this bug) is available at http://www.eclipse.org/jdt/core/r3.2/index.php#UPDATES
Comment 12 Jerome Lanneluc CLA 2006-07-17 05:03:54 EDT
*** Bug 150745 has been marked as a duplicate of this bug. ***
Comment 13 Frederic Fusier CLA 2006-08-07 09:20:09 EDT
Verified for 3.3 M1 using build I20060807-0010.
Comment 14 David Audel CLA 2006-09-12 08:34:56 EDT
Verified for 3.2.1 using build M20060908-1655
Comment 15 Jerome Lanneluc CLA 2008-02-28 04:55:26 EST
*** Bug 151905 has been marked as a duplicate of this bug. ***