View | Details | Raw Unified | Return to bug 55691
Collapse All | Expand All

(-)java/javax/el/ArrayELResolver.java (-4 / +51 lines)
Lines 88-97 Link Here
88
88
89
            int idx = coerce(property);
89
            int idx = coerce(property);
90
            checkBounds(base, idx);
90
            checkBounds(base, idx);
91
            if (value != null &&
91
            if (value != null) {
92
                    !base.getClass().getComponentType().isAssignableFrom(
92
                if(!typesAreAssignable(base.getClass().getComponentType(),
93
                            value.getClass())) {
93
                                       value.getClass()))
94
                throw new ClassCastException(Util.message(context,
94
                    throw new ClassCastException(Util.message(context,
95
                        "objectNotAssignable", value.getClass().getName(),
95
                        "objectNotAssignable", value.getClass().getName(),
96
                        base.getClass().getComponentType().getName()));
96
                        base.getClass().getComponentType().getName()));
97
            }
97
            }
Lines 99-104 Link Here
99
        }
99
        }
100
    }
100
    }
101
101
102
    /**
103
     * A method that replaces Class.isAssignableFrom with one that can
104
     * successfully compare primitive types with their wrapper types.
105
     *
106
     * @param a A Class
107
     * @param b A Class
108
     *
109
     * @return <code>true</code> if type <code>b</code> can be
110
     *         assigned a value of type <code>a</code> (with possible
111
     *         auto-boxing).
112
     */
113
    private boolean typesAreAssignable(Class<?> a, Class<?> b) {
114
        if(a.isPrimitive())
115
            a = getPrimitiveWrapperType(a);
116
        if(b.isPrimitive())
117
            b = getPrimitiveWrapperType(b);
118
119
        return a.isAssignableFrom(b);
120
    }
121
122
    /**
123
     * Converts a primitive type to its wrapper type.
124
     * @param c A primitive Class (e.g. {@see java.lang.Integer#TYPE})
125
     * @return The primitive wrapper class for <code>c</code>
126
     *         (e.g. {@see java.lang.Integer.class}.
127
     */
128
    private Class<?> getPrimitiveWrapperType(Class<?> c) {
129
        if(Integer.TYPE == c)
130
            return Integer.class;
131
        if(Long.TYPE == c)
132
            return Long.class;
133
        if(Double.TYPE == c)
134
            return Double.class;
135
        if(Float.TYPE == c)
136
            return Float.class;
137
        if(Byte.TYPE == c)
138
            return Byte.class;
139
        if(Short.TYPE == c)
140
            return Short.class;
141
        if(Character.TYPE == c)
142
            return Character.class;
143
        if(Boolean.TYPE == c)
144
            return Boolean.class;
145
146
        throw new IllegalArgumentException(c + " is not a primitive type");
147
    }
148
102
    @Override
149
    @Override
103
    public boolean isReadOnly(ELContext context, Object base, Object property) {
150
    public boolean isReadOnly(ELContext context, Object base, Object property) {
104
        if (context == null) {
151
        if (context == null) {

Return to bug 55691