Skip to content

Use standard String comparison in ExtendedBeanInfo.PropertyDescriptorComparator #31866

Description

@scqiu

Affects: 5.3.20


The compare method of ExtendedBeanInfo.PropertyDescriptorComparator class

public int compare(PropertyDescriptor desc1, PropertyDescriptor desc2) {
			String left = desc1.getName();
			String right = desc2.getName();
			byte[] leftBytes = left.getBytes();
			byte[] rightBytes = right.getBytes();
			for (int i = 0; i < left.length(); i++) {
				if (right.length() == i) {
					return 1;
				}
				int result = leftBytes[i] - rightBytes[i];
				if (result != 0) {
					return result;
				}
			}
			return left.length() - right.length();
		}

For some string encode of utf-8, the length of left is not equal to the length of leftBytes.

The for-loop should use the length of leftBytes.

For example if the left is "指标大类", the right is "指标名称". This method will return 0. Obviously it's wrong.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions