Bug 79545 - Eclipse vs Sun JDK: different class files from the same source code
Summary: Eclipse vs Sun JDK: different class files from the same source code
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-26 05:58 EST by Robert Kwolek CLA
Modified: 2004-12-15 07:41 EST (History)
0 users

See Also:


Attachments
Apply on HEAD (751 bytes, patch)
2004-11-26 14:10 EST, Olivier Thomann CLA
no flags Details | Diff
Apply on HEAD (11.91 KB, patch)
2004-11-26 14:19 EST, Olivier Thomann CLA
no flags Details | Diff
Apply on jdt.core.test.compiler (1.10 KB, patch)
2004-11-26 14:22 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 Robert Kwolek CLA 2004-11-26 05:58:20 EST
Compile the source code below in Eclipse and run it.
Do the same using Sun JDK (1.4.1 or 1.5).
The results are different.
The problem is connected with +' ': Eclipse treats it as ' ' but Sun JDK 
converts that space into 32 (+' ' => + (int) ' ' => +32 => 32) (which IMHO is 
correct).

PS. I'm not sure if I picked the proper product (JDT)...

The source code:

public class CharIntTest
{
    /**
     * Eclipse value: " "
     * JDK value:     "32"
     */
    public static String C = "" + +' ';
    /**
     * Eclipse value: "32"
     * JDK value:     "32"
     */
    public static String I = "" + +32;

    public static void main(String[] args)
    {
        System.out.println(C);
        System.out.println(I);
    }
}
Comment 1 Olivier Thomann CLA 2004-11-26 08:46:50 EST
I will investigate.
Comment 2 Olivier Thomann CLA 2004-11-26 13:27:52 EST
This is a bug with the computation of a compile-time constant with an unary
expression.
If (+' ') is replaced with (' '), then the Eclipse compiler behaves well. I am
not sure why +' ' would be treated as a char.
I will check the JLS.
Comment 3 Olivier Thomann CLA 2004-11-26 14:10:32 EST
Created attachment 16176 [details]
Apply on HEAD
Comment 4 Olivier Thomann CLA 2004-11-26 14:18:33 EST
We can also get rid of the operator parameter in the compute constant methods.
Comment 5 Olivier Thomann CLA 2004-11-26 14:19:17 EST
Created attachment 16177 [details]
Apply on HEAD

New patch. Apply on the jdt/core project.
Comment 6 Olivier Thomann CLA 2004-11-26 14:22:29 EST
Created attachment 16178 [details]
Apply on jdt.core.test.compiler
Comment 7 Olivier Thomann CLA 2004-11-26 15:49:50 EST
Fixed and released in HEAD.
Regression test added.
Comment 8 Jerome Lanneluc CLA 2004-12-15 07:41:36 EST
Verified (in I20041214-2000) that the provided test case has the following
output when compiled with Eclipse:
32
32