Details
-
Bug
-
Status: Closed
-
Trivial
-
Resolution: Won't Fix
-
None
-
None
-
None
Description
example
package cn; public class A { private Integer id; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; A other = (A) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } }
<%@page import="java.util.ArrayList"%> <%@page import="java.util.List"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="cn.A"%> <%@taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% A a1 = new A(); a1.setId(1); A a2 = new A(); a2.setId(2); List<A> list = new ArrayList(); list.add(a1); list.add(a2); request.setAttribute("list", list); %> <s:iterator value="#request.list" var="a"> <s:property value="#list.contains(#a)"/><br/> </s:iterator> </body> </html>
exptect result:
true
true
but was :
true
only one!!!
on config struts.el.throwExceptionOnFailure=true , result is :
invalid comparison: cn.A and cn.A - Class: ognl.OgnlOps
File: OgnlOps.java
Method: compareWithConversion
compareWithConversion :
case NONNUMERIC: if ( ( t1 == NONNUMERIC ) && ( t2 == NONNUMERIC ) ) { if (!(v1 instanceof Comparable)) { result = -1; break; } if ( ( v1 instanceof Comparable ) && v1.getClass().isAssignableFrom( v2.getClass() ) ) { result = ( (Comparable) v1 ).compareTo( v2 ); break; } throw new IllegalArgumentException( "invalid comparison: " + v1.getClass().getName() + " and " + v2.getClass().getName() ); } // else fall through
add code :
if (!(v1 instanceof Comparable)) { result = -1; break; }
if class not implement Comparable interface , return -1(false)。
Attachments
Issue Links
- is depended upon by
-
WW-4207 Upgrade to OGNL 3.0.11
- Closed