You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2025/05/18 16:23:00 UTC
[jira] [Commented] (CODEC-329) org.apache.commons.codec.language.DoubleMetaphone.handleZ(String,DoubleMetaphoneResult,int,boolean) does not process lowercase 'zh' correctly
[ https://issues.apache.org/jira/browse/CODEC-329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17952459#comment-17952459 ]
Gary D. Gregory commented on CODEC-329:
---------------------------------------
In general, I don't think that testing the internals of this class through reflection is helpful here since it might not reflect a bug in the client call-site because additional processing may not surface an actual issue.
Do you have an actual failing example?
- Please use JUnit 5
- This seems confusing and counterproductive:
{code:java}
catch (Exception e)
{ e.printStackTrace(); }
}
{code}
> 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
> 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)