harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Zhou (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-6244) [classlib][beans] java.beans.XMLEncoder fails to write SystemColor.activeCaption object correctly
Date Thu, 25 Jun 2009 08:59:07 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-6244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12723960#action_12723960
] 

Kevin Zhou commented on HARMONY-6244:
-------------------------------------

I investigate this code in BEAN module, and find the problem cause locates in java.beans.StaticFieldPersistenceDelegate.
For the java.awt.SystemColor class, its persistence delegate is AwtSystemColorPersistenceDelegate
which extends StaticFieldPersistenceDelegate. When AwtSystemColorPersistenceDelegate is referred
in the code, its super.init(SystemColor) method [1] is called to cache the names of all the
static fields in SystemColor. 
OK, the root cause is the hashCode method of SystemColor. SystemColor.activeCaption.hashCode()
returns the same hash value as SystemColor.textHighlight.hashCode() method. Thus, in the cache,
it put SystemColor.textHighlight and replace the previous SystemColor.activeCaption.

[1] java.beans.StaticFieldPersistenceDelegate.init(Clazz clz) method
static void init(Class<?> clz) {
    Field[] field = clz.getFields();
    for (int i = 0; i < field.length; i++) {
        Object value = null;
        try {
            value = field[i].get(clz);
        } catch (Exception e) {
            return;
        }
        if (value.getClass() == clz) {
            pairs.put(value, field[i].getName());
        }
    }
}

> [classlib][beans] java.beans.XMLEncoder fails to write SystemColor.activeCaption object
correctly
> -------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6244
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6244
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M10
>            Reporter: Kevin Zhou
>             Fix For: 5.0M11
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Given a test case [1], RI outputs differently from HARMONY.
> RI's outputs:
> <java version="1.5.0_06" class="java.beans.XMLDecoder"> 
>     <object class="java.awt.SystemColor" field="activeCaption"/>
> </java> 
> while HARMONY outputs:
> <java version="1.5.0" class="java.beans.XMLDecoder">
>     <object class="java.awt.SystemColor" field="textHighlight"/> 
> </java>
> [1] Test Case:
> public void test_writeObject_java_awt_SystemColor() {
>     ByteArrayOutputStream bos = new ByteArrayOutputStream();
>     XMLEncoder encoder = new XMLEncoder(bos);
>     encoder.writeObject(SystemColor.activeCaption);
>     encoder.close();
>     System.out.println(bos.toString());
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message