From dev-return-7883-apmail-directory-dev-archive=directory.apache.org@directory.apache.org Thu Sep 15 15:33:26 2005 Return-Path: Delivered-To: apmail-directory-dev-archive@www.apache.org Received: (qmail 62865 invoked from network); 15 Sep 2005 15:33:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Sep 2005 15:33:26 -0000 Received: (qmail 81578 invoked by uid 500); 15 Sep 2005 15:33:26 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 81387 invoked by uid 500); 15 Sep 2005 15:33:24 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 81374 invoked by uid 99); 15 Sep 2005 15:33:24 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Sep 2005 08:33:24 -0700 X-ASF-Spam-Status: No, hits=1.9 required=10.0 tests=DNS_FROM_RFC_POST,FROM_ENDS_IN_NUMS,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of aok123@bellsouth.net designates 205.152.59.64 as permitted sender) Received: from [205.152.59.64] (HELO imf16aec.mail.bellsouth.net) (205.152.59.64) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Sep 2005 08:33:31 -0700 Received: from ibm56aec.bellsouth.net ([65.80.200.112]) by imf16aec.mail.bellsouth.net with ESMTP id <20050915153319.UILC26600.imf16aec.mail.bellsouth.net@ibm56aec.bellsouth.net> for ; Thu, 15 Sep 2005 11:33:19 -0400 Received: from [172.16.1.152] (really [65.80.200.112]) by ibm56aec.bellsouth.net with ESMTP id <20050915153318.VAPR4982.ibm56aec.bellsouth.net@[172.16.1.152]> for ; Thu, 15 Sep 2005 11:33:18 -0400 Message-ID: <4329943E.8050102@bellsouth.net> Date: Thu, 15 Sep 2005 11:33:18 -0400 From: Alex Karasulu User-Agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Apache Directory Developers List Subject: Re: patch - fixed ClassCastException issuing from ValueNormalizingVisitor.java in core References: <43293A3F.9000209@atlassian.com> In-Reply-To: <43293A3F.9000209@atlassian.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Nick you're an Atlassian guy, why not use JIRA for patches :). Alex Nick Faiz wrote: > Hi, > > I found a ClassCastException being issued on > ValueNormalizingVisitor.java in core. > > It looks like an easy fix; wrap the cast in a type check. > > if (node instanceof BranchNode) > { > BranchNode bnode = ( BranchNode ) node; > final int size = bnode.getChildren().size(); > for ( int ii = 0; ii < size ; ii++ ) > { > visit( ( ExprNode ) bnode.getChildren().get( ii ) ); > } > } > > I think this is okay because it was trying to cast a PresenceNode > (LeafNode) into a branch node. This looks like normal tree traversal, > so I assume it's okay to not visit any further nodes if the node is a > LeafNode. > > Cheers, > Nick > >------------------------------------------------------------------------ > >/* > * Copyright 2004 The Apache Software Foundation > * > * Licensed under the Apache License, Version 2.0 (the "License"); > * you may not use this file except in compliance with the License. > * You may obtain a copy of the License at > * > * http://www.apache.org/licenses/LICENSE-2.0 > * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > * See the License for the specific language governing permissions and > * limitations under the License. > * > */ >package org.apache.ldap.server.normalization; > > >import org.apache.ldap.common.filter.FilterVisitor; >import org.apache.ldap.common.filter.ExprNode; >import org.apache.ldap.common.filter.BranchNode; >import org.apache.ldap.common.filter.SimpleNode; >import org.apache.ldap.common.name.NameComponentNormalizer; >import org.slf4j.Logger; >import org.slf4j.LoggerFactory; > >import javax.naming.NamingException; >import java.util.ArrayList; > > >/** > * A filter visitor which normalizes leaf node values as it visits them. > * > * @author Apache Directory Project > * @version $Rev$ > */ >public class ValueNormalizingVisitor implements FilterVisitor >{ > private final static Logger log = LoggerFactory.getLogger( ValueNormalizingVisitor.class ); > private final NameComponentNormalizer ncn; > > > public ValueNormalizingVisitor( NameComponentNormalizer ncn ) > { > this.ncn = ncn; > } > > > public void visit( ExprNode node ) > { > if ( node instanceof SimpleNode ) > { > SimpleNode snode = ( SimpleNode ) node; > String normalized = null; > > try > { > if ( Character.isDigit( snode.getAttribute().charAt( 0 ) ) ) > { > normalized = ncn.normalizeByOid( snode.getAttribute(), snode.getValue() ); > } > else > { > normalized = ncn.normalizeByName( snode.getAttribute(), snode.getValue() ); > } > } > catch ( NamingException e ) > { > log.error( "Failed to normalize filter value: " + e.getMessage(), e ); > throw new RuntimeException( e.getMessage() ); > } > > snode.setValue( normalized ); > return; > } > > if (node instanceof BranchNode) > { > BranchNode bnode = ( BranchNode ) node; > final int size = bnode.getChildren().size(); > for ( int ii = 0; ii < size ; ii++ ) > { > visit( ( ExprNode ) bnode.getChildren().get( ii ) ); > } > } > } > > > public boolean canVisit( ExprNode node ) > { > return node instanceof BranchNode || node instanceof SimpleNode; > } > > > public boolean isPrefix() > { > return false; > } > > > public ArrayList getOrder( BranchNode node, ArrayList children ) > { > return children; > } >} > >