[ https://issues.apache.org/jira/browse/CODEC-329?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory resolved CODEC-329. ----------------------------------- Resolution: Not A Bug > org.apache.commons.codec.language.DoubleMetaphone.handleZ(String,DoubleMetaphoneResult,int,boolean) > does not process lowercase 'zh' correctly > --------------------------------------------------------------------------------------------------------------------------------------------- > > Key: CODEC-329 > URL: https://issues.apache.org/jira/browse/CODEC-329 > Project: Commons Codec > Issue Type: Bug > Affects Versions: 1.18.0 > Environment: JDK 8, MacOS > Reporter: Dianshu Liao > Priority: Major > Attachments: Screenshot 2025-05-19 at 12.43.33 am.png > > > File: src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java > Method: private int handleZ(final String value, final DoubleMetaphoneResult > result, int index, final boolean slavoGermanic) > h1. Problem > The method {{"handleZ"}} only handles uppercase {{'H'}} in the {{"ZH"}} > pattern. > When passing a lowercase input such as {{{}"zhang"{}}}, it fails to recognize > {{"zh"}} as a match, and only increments the index by 1 instead of 2. > This results in incorrect behavior compared to how {{"ZH"}} is documented and > expected to be handled (i.e., as a {{"J"}} sound with index increased by 2). > > h1. Test Code > package org.apache.commons.codec.language; > import org.apache.commons.codec.language.DoubleMetaphone; > import > org.apache.commons.codec.language.DoubleMetaphone.DoubleMetaphoneResult; > import org.junit.Test; > import java.lang.reflect.Method; > import static org.junit.Assert.assertEquals; > public class language_DoubleMetaphone_handleZ_Test { > @Test(timeout = 4000) > public void testHandleZ() { > DoubleMetaphone doubleMetaphone = new DoubleMetaphone(); > DoubleMetaphoneResult result = doubleMetaphone.new > DoubleMetaphoneResult(0); // Corrected instantiation with an integer argument > String value = "zhang"; // example to test the Z handling > int index = 0; // starting index > boolean slavoGermanic = false; // testing with slavoGermanic set to > false > try { > // Accessing the private method using reflection > Method method = > DoubleMetaphone.class.getDeclaredMethod("handleZ", String.class, > DoubleMetaphoneResult.class, int.class, boolean.class); > method.setAccessible(true); // making the method accessible > int newIndex = (int) method.invoke(doubleMetaphone, value, > result, index, slavoGermanic); > > // Expected behavior, index should increase by 2 because the next > character is 'H' > assertEquals(2, newIndex); > > } catch (Exception e) { > e.printStackTrace(); > } > } > h1. } > Expected Result > Index should increase by *2* > > h1. Actual Result > Index increases by *1* -- This message was sent by Atlassian Jira (v8.20.10#820010)