Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 240449 - "Export.. Deployable plug-ins and fragments" encodes Strings in class files wrong
Summary: "Export.. Deployable plug-ins and fragments" encodes Strings in class files w...
Status: RESOLVED DUPLICATE of bug 155015
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: PDE-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-11 04:02 EDT by Holger Mense CLA
Modified: 2008-07-14 10:09 EDT (History)
4 users (show)

See Also:


Attachments
Runnable example and full source. (892.09 KB, application/octet-stream)
2008-07-11 04:02 EDT, Holger Mense CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Holger Mense CLA 2008-07-11 04:02:42 EDT
Created attachment 107182 [details]
Runnable example and full source.

Build ID: I20080617-2000

Steps to reproduce:
1. Start Eclipse 3.4 on Windows XP.

2. Check Eclipse configuration details: beside some other settings, file.encoding is set to Cp1252.

3. Create a new plug-in project "com.example.utf8" in workspace.

4. Set text file encoding for source files in this project to UTF-8.

5. Implement a BundleActivator which does the following:


public void start() throws Exception
{       
        String data = "§";
        System.out.println("data = "+data);
        System.out.println("data.length() = "+data.length() );
        
        byte[] dataBytes = data.getBytes();
        
        System.out.print("data.getBytes() = ");
        for (int i=0; i<dataBytes.length; i++)
            System.out.print(dataBytes[i]+" ");            
}

6. Execute the plug-in inside an OSGi framework run configuration in Eclipse. It prints:
data = -º
data.length() = 1
data.getBytes() = -62 -89 

7. Export the bundle via "Export.. Deployable plug-ins and fragments".

8. Start Equinox framework with the exported bundle on a command shell:
# java -Dfile.encoding=UTF-8 -Dosgi.bundles=com.example.utf8_1.0.0.jar@start -jar plugins/org.eclipse.osgi_3.4.0.v20080605-1900.jar
It prints:
data = +é-º
data.length = 2
data.getBytes() = -61 -126 -62 -89

This output is wrong. The String has been enhanced by two bytes. The output should be the same as in in step 6.


Workaround:
1. Close Eclipse.

2. Edit eclipse.ini. Add the following line after the parameter "-vmwargs":
-Dfile.encoding=UTF-8

3. Start Eclipse.

4. Export the plug-in again.

5. Start Equinox framework with the exported bundle on a command shell. It prints:
data.getBytes() = -62 -89 


More information:
The "Export.. Deployable plug-ins and fragments" function recompiles the source files in the project. 
If the eclipse file.encoding parameter is set to Cp1252, the String with the special character in the class file
is enhanced by two bytes. This leads to the wrong output. 

If you compare both compiled class files you will see, that their is different by two bytes. When comparing both class files on hex basis, you can see, that this two bytes are added at the String definition.

Running the code inside Eclipse always returns correct output.
Comment 1 Gunnar Wagenknecht CLA 2008-07-11 07:15:18 EDT
"Deployable plug-ins and fragments" is provided by PDE. I thought you ment the JAR export wizard. Sorry for the confusion.
Comment 2 Chris Aniszczyk CLA 2008-07-14 10:09:31 EDT
PDE Build isn't workspace aware. This is a dupe.

A way to get encodings to work is to set something like this in your project build.properties...

javacCustomEncodings.. = src/org/foo[US-ASCII],\
                         src/org/foo/bar.java[ISO-8859-1]

*** This bug has been marked as a duplicate of bug 155015 ***