struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "zhangkaitao (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4230) ognl use in expression bug
Date Mon, 21 Oct 2013 04:38:43 GMT

    [ https://issues.apache.org/jira/browse/WW-4230?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13800350#comment-13800350
] 

zhangkaitao commented on WW-4230:
---------------------------------

 OGNL is an expression language  , but implements in java, used in jsp or java。  and,
don't say its limitations in doc, make me confusion。

In addition:
Comparable javadoc did not say the same type must be。

so code should be:
{code}
case NONNUMERIC:
                if ((t1 == NONNUMERIC) && (t2 == NONNUMERIC)) {
                    if ((v1 instanceof Comparable)) {
                        result = ((Comparable) v1).compareTo(v2);
                        break;
                    } else {
                        result = -1;
                        break;
                    }
                }
                // else fall through
{code}

> ognl use  in  expression bug
> ----------------------------
>
>                 Key: WW-4230
>                 URL: https://issues.apache.org/jira/browse/WW-4230
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Other
>            Reporter: zhangkaitao
>            Assignee: Lukasz Lenart
>            Priority: Trivial
>
> example
> {code}
> 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;
> 	}
> 	
> 	
> }
> {code}
> {code}
> <%@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>
> {code}
> 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 :
> {code}
> 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
> {code}
> add code :
> {code}
>                         if (!(v1 instanceof Comparable)) {
>                     		result = -1;
>                     		break;
>                     	}
> {code}
> if class not implement Comparable interface , return -1(false)。  



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message