harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-6289) Inconsistent behaviour of ternary operator and types
Date Sun, 02 Aug 2009 14:19:14 GMT
Inconsistent behaviour of ternary operator and types
----------------------------------------------------

                 Key: HARMONY-6289
                 URL: https://issues.apache.org/jira/browse/HARMONY-6289
             Project: Harmony
          Issue Type: Bug
          Components: JDK
    Affects Versions: 5.0M10
         Environment: Eclipse Java Compiler 0.894_R34x, 3.4.2 release, Copyright IBM Corp
2000, 2008. All rights reserved.

WinXP/SP3
            Reporter: Sebb


Compile the following class using: javac -5 TernaryType.java

==== cut here ====
import java.util.*;

class TernaryType {
    
    Map<String, Object> functions;

    public void setFunctionsBug(Map<String, Object> funcs) {
        functions = funcs != null ? funcs : Collections.emptyMap();
    }
    public void setFunctionsOK(Map<String, Object> funcs) {
		if (funcs != null) {
            functions = funcs;
        } else {
			functions = Collections.emptyMap();
		}
    }
}
=== cut here ===

Compiler output is:

1. ERROR in TernaryType.java (at line 8)
        functions = funcs != null ? funcs : Collections.emptyMap();
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type mismatch: cannot convert from Map<capture#1-of ? extends Object,Object> to Map<String,Object>

The two methods have exactly the same behaviour, yet only the ternary version generates an
error.

Note that the Sun 1.5 and 1.6 compilers behave the same way, but it still seems like a bug
to me.

-- 
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