Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptff2004-07-22 16:11:57 +0000
committerptff2004-07-22 16:11:57 +0000
commit535993d74276ab13aa2436983f36b09e77a7117c (patch)
tree12b8854715b13013e1355ca7765126732439c49a
parent27790bb7f13abd4401c1f3af3fa8b8b1472c8cb6 (diff)
downloadeclipse.jdt.core-535993d74276ab13aa2436983f36b09e77a7117c.tar.gz
eclipse.jdt.core-535993d74276ab13aa2436983f36b09e77a7117c.tar.xz
eclipse.jdt.core-535993d74276ab13aa2436983f36b09e77a7117c.zip
70598
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/EncodingTests.java71
-rw-r--r--org.eclipse.jdt.core/buildnotes_jdt-core.html4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java4
3 files changed, 53 insertions, 26 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/EncodingTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/EncodingTests.java
index f455699837..95705f3574 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/EncodingTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/EncodingTests.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.model;
+import java.io.File;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import junit.framework.Test;
@@ -51,7 +53,7 @@ public class EncodingTests extends ModifyingResourceTests {
// All specified tests which do not belong to the class are skipped...
static {
// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
-// testsNames = new String[] { "testBug66898", "testBug66898b" };
+// testsNames = new String[] { "testBug70598" };
// Numbers of tests to run: "test<number>" will be run for each number of this array
// testsNumbers = new int[] { 2, 12 };
// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last }
@@ -89,6 +91,29 @@ public class EncodingTests extends ModifyingResourceTests {
this.encodingJavaProject.close();
}
+ void compareContents(ICompilationUnit cu, String encoding) throws JavaModelException {
+ // Compare source strings
+ String source = cu.getSource();
+ String systemSourceRenamed = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(source);
+ IFile file = (IFile) cu.getUnderlyingResource();
+ String renamedContents = new String (Util.getResourceContentsAsCharArray(file));
+ renamedContents = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(renamedContents);
+ assertEquals("Encoded UTF-8 source should have been decoded the same way!", renamedContents, systemSourceRenamed);
+ // Compare bytes array
+ byte[] renamedSourceBytes = null;
+ try {
+ renamedSourceBytes = source.getBytes(encoding);
+ }
+ catch (UnsupportedEncodingException uue) {
+ }
+ assertNotNull("Unsupported encoding: "+encoding, renamedSourceBytes);
+ byte[] renamedEncodedBytes = Util.getResourceContentsAsByteArray(file);
+ assertEquals("Wrong size of encoded string", renamedEncodedBytes.length, renamedSourceBytes.length);
+ for (int i = 0, max = renamedSourceBytes.length; i < max; i++) {
+ assertTrue("Wrong size of encoded character at " + i, renamedSourceBytes[i] == renamedEncodedBytes[i]);
+ }
+ }
+
/**
* Check that the compilation unit is saved with the proper encoding.
*/
@@ -681,26 +706,26 @@ public class EncodingTests extends ModifyingResourceTests {
cu.delete(true, null);
deleteFolder("/Encoding/src/tmp");
}
- void compareContents(ICompilationUnit cu, String encoding) throws JavaModelException {
- // Compare source strings
- String source = cu.getSource();
- String systemSourceRenamed = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(source);
- IFile file = (IFile) cu.getUnderlyingResource();
- String renamedContents = new String (Util.getResourceContentsAsCharArray(file));
- renamedContents = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(renamedContents);
- assertEquals("Encoded UTF-8 source should have been decoded the same way!", renamedContents, systemSourceRenamed);
- // Compare bytes array
- byte[] renamedSourceBytes = null;
- try {
- renamedSourceBytes = source.getBytes(encoding);
- }
- catch (UnsupportedEncodingException uue) {
- }
- assertNotNull("Unsupported encoding: "+encoding, renamedSourceBytes);
- byte[] renamedEncodedBytes = Util.getResourceContentsAsByteArray(file);
- assertEquals("Wrong size of encoded string", renamedEncodedBytes.length, renamedSourceBytes.length);
- for (int i = 0, max = renamedSourceBytes.length; i < max; i++) {
- assertTrue("Wrong size of encoded character at " + i, renamedSourceBytes[i] == renamedEncodedBytes[i]);
- }
- }
+
+ /**
+ * Test case for bug 70598: [Encoding] ArrayIndexOutOfBoundsException while testing BOM on *.txt files
+ * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=70598)
+ */
+ public void testBug70598() throws JavaModelException, CoreException, IOException {
+
+ // Create empty file
+ IFile emptyFile = createFile("/Encoding/src/testUTF8BOM/Empty.java", new byte[0]);
+
+ // Test read empty content using io file
+ File file = new File(this.encodingProject.getLocation().toString(), emptyFile.getProjectRelativePath().toString());
+ char[] fileContents = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(file, "UTF-8");
+ assertEquals("We should not get any character!", "", new String(fileContents));
+
+ // Test read empty content using io file
+ char[] ifileContents =Util.getResourceContentsAsCharArray(emptyFile, "UTF-8");
+ assertEquals("We should not get any character!", "", new String(ifileContents));
+
+ // Delete empty file
+ deleteFile(file);
+ }
}
diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html
index ee5a584210..c8106d52c2 100644
--- a/org.eclipse.jdt.core/buildnotes_jdt-core.html
+++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html
@@ -51,7 +51,9 @@ for any serializable class which could be surfaced through APIs.</li>
</ul>
<h3>Problem Reports Fixed</h3>
-<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=70403">70403</a>
+<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=70598">70598</a>
+[Encoding] ArrayIndexOutOfBoundsException while testing BOM on *.txt files
+<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=70403">70403</a>
Hardcoded paths make copy of workspace unusable and eventually corrupt the original one
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=69152">69152</a>
[NPE] An internal error occurred during: "Override indicator installation job".
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java
index 957c329cde..94b7567a0f 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java
@@ -328,7 +328,7 @@ public class Util implements SuffixConstants {
// Do not keep first character for UTF-8 BOM encoding
int start = 0;
- if ("UTF-8".equals(encoding)) { //$NON-NLS-1$
+ if (contentsLength > 0 && "UTF-8".equals(encoding)) { //$NON-NLS-1$
if (contents[0] == 0xFEFF) { // if BOM char then skip
contentsLength--;
start = 1;
@@ -355,7 +355,7 @@ public class Util implements SuffixConstants {
}
// Do not keep first character for UTF-8 BOM encoding
int start = 0;
- if ("UTF-8".equals(encoding)) { //$NON-NLS-1$
+ if (length > 0 && "UTF-8".equals(encoding)) { //$NON-NLS-1$
if (contents[0] == 0xFEFF) { // if BOM char then skip
len--;
start = 1;

Back to the top