Bug 259435 - [compiler] No compiler error/warning for invalid encoding in Java source files
Summary: [compiler] No compiler error/warning for invalid encoding in Java source files
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2008-12-20 03:56 EST by Robin Rosenberg CLA
Modified: 2023-08-23 14:22 EDT (History)
3 users (show)

See Also:


Attachments
ISO-Latin-1 encoded java file (65 bytes, text/plain)
2008-12-20 03:56 EST, Robin Rosenberg CLA
no flags Details
Proposed fix (3.92 KB, patch)
2009-01-29 14:12 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Rosenberg CLA 2008-12-20 03:56:26 EST
Created attachment 120993 [details]
ISO-Latin-1 encoded java file

Build ID: I20080617-2000

Steps To Reproduce:
Create a file using ISO-8859-1 characters
Loading it into an Eclipse using UTF-8 as it's default encoding.
No warning or error is given

SUN's javac gives a warning

$ javac Bad.java
Bad.java:2: warning: unmappable character for encoding UTF8
    String foo = "�"; // A with ring on top
                  ^
1 warning

More information:
Comment 1 Jerome Lanneluc CLA 2009-01-07 11:10:27 EST
The batch compiler doesn't report the problem either, whereas javac 6 does report the problem.
Comment 2 Philipe Mulet CLA 2009-01-29 11:43:17 EST
Pls investigate. I was hoping an encoding error to be surfaced.
Comment 3 Olivier Thomann CLA 2009-01-29 11:51:13 EST
You want to consider the batch mode or the IDE mode or both.
Comment 4 Olivier Thomann CLA 2009-01-29 12:31:17 EST
The API we use to get the file contents doesn't report any encoding error in this case.
We could change the way we retrieve the contents, but since the compiler needs to be compliant with 1.3 API, we cannot use nio API.
We could envision using the reflect API in order to know if nio are available.

javac doesn't have this limitation.

For the builder, we get the contents through the IFile API that doesn't report encoding errors. This would be an issue for Platform/Resources.
Comment 5 Olivier Thomann CLA 2009-01-29 13:11:06 EST
In fact, IFile.getContents() only returns an InputStream.
So the code to diagnose encoding errors is inside the jdt.core bundle.
We could fix the builder to use nio code since the builder can use 1.4 code.

Only the batch compiler still has an issue.
Comment 6 Olivier Thomann CLA 2009-01-29 14:12:37 EST
Created attachment 124187 [details]
Proposed fix

Simple fix for the java builder. With this change, the java builder will abort the compilation because the source file can no longer be read.

This doesn't fix the batch compiler due to the nio usage limitation.
Comment 7 Olivier Thomann CLA 2009-01-29 14:22:39 EST
Note that the patch now prevents the file from being read inside the java builder. This might be too strong. We might want to report only a warning.

Let me know the way you prefer the error from being reported.
Comment 8 Chuck Simpson CLA 2009-03-18 11:20:15 EDT
This bug also causes problems when initiating an Ant build from Eclipse. When the compiler encounters problem characters, in this case 0x92 and 0x93, the compiler bails but the error is not reported because the console throws an Exception. See below. The result is that the Ant build hangs until it is manually terminated.

Here is the only stack trace I found for this problem.

Eclipse Platform
Version: 3.4.2
Build id: M20090211-1700

!ENTRY org.eclipse.ui.console 4 2 2009-03-17 17:51:27.894
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.ui.console".
!STACK 0
org.eclipse.swt.SWTException: Device is disposed
	at org.eclipse.swt.SWT.error(SWT.java:3777)
	at org.eclipse.swt.SWT.error(SWT.java:3695)
	at org.eclipse.swt.SWT.error(SWT.java:3666)
	at org.eclipse.swt.widgets.Display.error(Display.java:1180)
	at org.eclipse.swt.widgets.Display.asyncExec(Display.java:648)
	at org.eclipse.ui.internal.console.ConsoleDropDownAction.consolesRemoved(ConsoleDropDownAction.java:150)
	at org.eclipse.ui.internal.console.ConsoleManager$ConsoleNotifier.run(ConsoleManager.java:154)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.ui.internal.console.ConsoleManager$ConsoleNotifier.notify(ConsoleManager.java:174)
	at org.eclipse.ui.internal.console.ConsoleManager.fireUpdate(ConsoleManager.java:262)
	at org.eclipse.ui.internal.console.ConsoleManager.removeConsoles(ConsoleManager.java:244)
	at org.eclipse.debug.internal.ui.views.console.ProcessConsoleManager.removeProcess(ProcessConsoleManager.java:98)
	at org.eclipse.debug.internal.ui.views.console.ProcessConsoleManager.removeLaunch(ProcessConsoleManager.java:81)
	at org.eclipse.debug.internal.ui.views.console.ProcessConsoleManager.shutdown(ProcessConsoleManager.java:198)
	at org.eclipse.debug.internal.ui.DebugUIPlugin.stop(DebugUIPlugin.java:388)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$3.run(BundleContextImpl.java:1050)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:1046)
	at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:457)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:531)
	at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1104)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.decFWSL(StartLevelManager.java:655)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:312)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.shutdown(StartLevelManager.java:257)
	at org.eclipse.osgi.framework.internal.core.SystemBundle.suspend(SystemBundle.java:236)
	at org.eclipse.osgi.framework.internal.core.Framework.shutdown(Framework.java:678)
	at org.eclipse.osgi.framework.internal.core.Framework.close(Framework.java:576)
	at org.eclipse.osgi.framework.internal.core.OSGi.close(OSGi.java:41)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.shutdown(EclipseStarter.java:424)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:200)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Comment 9 Eclipse Genie CLA 2019-09-08 12:38:42 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 10 Jay Arthanareeswaran CLA 2019-09-09 01:35:22 EDT
I presume this is still relevant. We do have a patch, but looks like it won't be sufficient for the scenario reported in comment #8.

It will be nice if someone can pick this up and provide a patch for both the batch compiler as well as the IDE.
Comment 11 Eclipse Genie CLA 2021-08-30 02:23:57 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 12 Eclipse Genie CLA 2023-08-23 14:22:46 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.