Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 37375

Summary: BIDI - Eclipse generates an exception when trying to save in UTF-8 Arabic locale
Product: [Eclipse Project] JDT Reporter: Nagia El Haraki <nharaki>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, rasham
Version: 2.1   
Target Milestone: 3.2   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:

Description Nagia El Haraki CLA 2003-05-08 05:26:48 EDT
When starting Eclipse in an Arabic locale with UTF-8 encoding, files in Cp1256 
and ISO-8859-6 format can be viewed when changing the workbench encoding. 
However, when modifying these files and attempting to save, it generates a 
MalformedInputException.

Here is the snapshot from the .log file

sun.io.MalformedInputException
	at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java(Compiled Code))
	at java.io.InputStreamReader.convertInto(InputStreamReader.java:152)
	at java.io.InputStreamReader.fill(InputStreamReader.java:201)
	at java.io.InputStreamReader.read(InputStreamReader.java:264)
	at org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray
(Util.java:270)
	at org.eclipse.jdt.internal.core.Util.getResourceContentsAsCharArray
(Util.java:631)
	at org.eclipse.jdt.internal.core.Util.getResourceContentsAsCharArray
(Util.java:620)
	at org.eclipse.jdt.internal.core.CompilationUnit.openBuffer
(CompilationUnit.java:671)
	at org.eclipse.jdt.internal.core.Openable.openWhenClosed
(Openable.java:393)
	at org.eclipse.jdt.internal.core.JavaElement.openHierarchy
(JavaElement.java:490)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo
(JavaElement.java:312)
	at org.eclipse.jdt.internal.core.JavaElement.getChildren
(JavaElement.java:254)
	at org.eclipse.jdt.internal.core.JavaElement.getChildrenOfType
(JavaElement.java:263)
	at org.eclipse.jdt.internal.core.CompilationUnit.getTypes
(CompilationUnit.java:522)
	at 
org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil.getMainType
(JavaElementUtil.java:98)
	at org.eclipse.jdt.ui.actions.UseSupertypeAction.canEnable
(UseSupertypeAction.java:125)
	at org.eclipse.jdt.ui.actions.UseSupertypeAction.selectionChanged
(UseSupertypeAction.java:77)
	at 
org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged
(SelectionDispatchAction.java:181)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged
(SelectionDispatchAction.java:176)
	at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:159)
	at org.eclipse.core.internal.runtime.InternalPlatform.run
(InternalPlatform.java(Inlined Compiled Code))
	at org.eclipse.core.runtime.Platform.run(Platform.java(Compiled Code))
	at org.eclipse.jface.viewers.Viewer.fireSelectionChanged
(Viewer.java:157)
	at org.eclipse.jface.viewers.StructuredViewer.updateSelection
(StructuredViewer.java:1290)
	at org.eclipse.jface.viewers.StructuredViewer.handleDoubleSelect
(StructuredViewer.java:588)
	at org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected
(StructuredViewer.java:684)
	at org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent
(OpenStrategy.java:187)
	at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.java:184)
	at org.eclipse.jface.util.OpenStrategy$1.handleEvent
(OpenStrategy.java:231)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java
(Compiled Code))
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java(Inlined 
Compiled Code))
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java
(Compiled Code))
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java
(Compiled Code))
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java
(Compiled Code))
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:1385)
	at org.eclipse.core.internal.boot.InternalBootLoader.run
(InternalBootLoader.java:845)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
	at java.lang.reflect.Method.invoke(Native Method)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
	at org.eclipse.core.launcher.Main.run(Main.java:747)
	at org.eclipse.core.launcher.Main.main(Main.java:583)
Comment 1 Dani Megert CLA 2003-05-08 05:49:54 EDT
The log is not directly related to save - it rather looks as being caused by
changing the selection. Can you list the exact steps and then first clear the
.log and try the steps you listed here. Also attach the ID of the build you are
using.
Comment 2 Kai-Uwe Maetzel CLA 2003-05-12 07:16:13 EDT
Here is my guess what happens: You view a compilation unit in an encoding that 
is different from the workbench's default encoding. You change the compilation 
unit. You save the compilation unit and the save operation succeeds. This 
means the cu is now saved in the same encoding that has been used for viewing 
it and that is different from the workbench's default encoding.

Cause by an event, the Java compiler tries to read the compilation unit from 
its file. The compiler uses the workbench's default encoding for that. As the 
file has been saved in a different encoding before, the read operation files 
with a MalFormedInputException.

When saving the compilation unit, the user has been notified that subsequent 
operation on this file might file because of the difference between the 
workbench's default encoding and the encoding used for saving the file.

This is a shortcoming of the current implementation which will be revisited 
during the 3.0 cycle.
Comment 3 Nagia El Haraki CLA 2003-05-14 06:26:07 EDT
What happened was that I already had the files written and saved under the 
specific encoding (whether Cp1256 or ISO-8859-6). When I open them from Eclipse 
(Arabic locale, UTF-8), it is not recognized. So, I go to Edit>Encoding and 
change it to the file's encoding.
When I modify the file and attempt to save it, that's when the given exception 
occurs.
It gives me first a warning that the file will saved under an encoding 
different than the default encoding, and when I proceed it gives the exception.

This means that if I am going to write my application under that specific 
encoding from scratch, it is not going to be saved.
Comment 4 Dani Megert CLA 2006-10-26 02:15:18 EDT
.
Comment 5 Dani Megert CLA 2006-10-26 02:19:08 EDT
Eclipse now shows a dialog when trying to save with an inappropriate encoding.