bitflicker64 opened a new pull request, #3457:
URL: https://github.com/apache/hugegraph/pull/3457
## Purpose of the PR
Found while scanning `hugegraph-commons/hugegraph-common` for small,
test-backed fixes. No issue was filed; each fix comes with a unit test that
fails on master, except the `NumericUtil` cleanup, which existing tests cover.
- `PerfUtil.FastMap.put` filled the next free fast slot even when the key
already sat in an earlier slot. `get()` checks the slots in order, so it kept
returning the old value, and `Stopwatch.child(name)` returned a watch that had
been replaced.
- `Stopwatch.Path.equals(null)` threw `NullPointerException` because it
compared hash codes before checking the type.
- `ReflectionUtil.getMethodsAnnotatedWith(Class, annotation, true)` threw
`NullPointerException` for an interface or for `Object`: their superclass is
null, and the loop only stopped at `Object`. The `CtClass` overload already
checks for null.
- `StringUtil.Chars` rejected an empty slice at the end of its array, so
`Chars.of("123").subSequence(3, 3)` threw instead of returning `""` as the
`CharSequence` contract requires. JDK code such as `Pattern.split` makes that
call.
- `NumericUtil.compareNumber` wrapped each `E.checkArgument` null check in
an `if` testing the same condition.
## Main Changes
- `FastMap.put`: update the slot that already holds the same key object
before taking a free one. Keys are compared by identity, as in `get()` and
`remove()`.
- `Path.equals`: check `instanceof` first.
- `ReflectionUtil`: also stop the superclass walk at null.
- `Chars`: accept `0 <= start <= length`. The existing end check still
requires `start <= end <= length`, so the only newly accepted input is the
empty slice at the end.
- `NumericUtil`: drop the redundant `if` wrappers; same checks and messages.
- Add 5 tests to `StopwatchTest`, `ReflectionUtilTest` and `StringUtilTest`,
all already in `UnitTestSuite`.
## Verifying these changes
- [ ] Trivial rework / code cleanup without any test coverage. (No Need)
- [ ] Already covered by existing tests, such as *(please modify tests
here)*.
- [x] Need tests and can be verified as follows:
- On master code all 5 new tests fail:
`testChildReplacedUnderSameNameIsReturned` (old watch returned),
`testPathEqualsNull` (NPE), `testGetMethodsAnnotatedWithOnInterface` and
`testGetMethodsAnnotatedWithOnObject` (NPE), `testCharsEmptySliceAtEnd`
(`Invalid start parameter 3`).
- Ran on Linux x86_64, OpenJDK 17.0.20.1, Maven 3.8.7, 2026-11-07, at
`d16c15534`:
`mvn -ntp -B test -pl hugegraph-commons/hugegraph-common -am
-Dtest=UnitTestSuite -DskipCommonsTests=false
-Dsurefire.failIfNoSpecifiedTests=false -Deditorconfig.skip=true`
Result: `UnitTestSuite` ran 397 tests, against 392 on master at
`cd7f1493b`, so all 5 new tests ran and passed.
Two existing tests fail on this host on master too, with the same
assertion: `MachineInfoTest.testGetIpAddressList:54` and
`testGetLocalAllInetAddress:74`. The host has interface addresses that the
test's IP patterns do not match; this PR does not touch those patterns.
- `-Deditorconfig.skip=true` is there because master fails the
editorconfig check on `helm/hugegraph/docs/rag.md` (missing final newline), a
file this PR does not touch.
## Does this PR potentially affect the following parts?
- [ ] Dependencies ([add/update
license](https://hugegraph.apache.org/docs/contribution-guidelines/contribute/#321-check-licenses)
info &
[regenerate_known_dependencies.sh](../install-dist/scripts/dependency/regenerate_known_dependencies.sh))
- [ ] Modify configurations
- [ ] The public API
- [ ] Other affects (typed here)
- [x] Nope
## Documentation Status
- [ ] `Doc - TODO`: required documentation is pending; complete it before
merging.
- [ ] `Doc - Done`: documentation is included here or linked below.
- [x] `Doc - No Need`: no user-visible documentation is affected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]