Skip to content

Conversation

@arrow1991
Copy link
Contributor

@arrow1991 arrow1991 commented Dec 29, 2025

What's the purpose of this PR

Refactor: string checks with idiomatic alternatives

Follow this checklist to help us incorporate your contribution quickly and easily:

  • [√] Read the Contributing Guide before making this pull request.
  • [√] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [√] Write necessary unit tests to verify the code.
  • [√] Run mvn clean test to make sure this pull request doesn't break anything.
  • [√] Update the CHANGES log.

Summary by CodeRabbit

  • Refactor
    • Replaced explicit size/length checks with idiomatic isEmpty()/isEmpty-like checks for collections and strings.
    • Converted string concatenations in debug/warn logs to parameterized logging placeholders.
    • Minor readability and consistency improvements; no behavioral or public API changes.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

This PR modernizes small idioms across the codebase: replaces collection/string length checks with isEmpty() and converts several string-concatenation logs to SLF4J parameterized logging. No public APIs or control flow semantics were changed.

Changes

Cohort / File(s) Summary
Collection isEmpty() (client internals)
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java, apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java
Replaced size() == 0 checks with isEmpty() for config-service list checks; behavior unchanged.
Collection isEmpty() (client & openapi)
apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/DefaultHttpClient.java, apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenPageDTO.java
Replaced size() > 0 / size() checks with !isEmpty() / isEmpty() for header and content presence checks; no logic change.
String/Set isEmpty() modernization
apollo-core/src/main/java/com/ctrip/framework/apollo/core/signature/Signature.java, apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/StringUtils.java, apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ApolloThreadFactory.java
Replaced length() > 0 and size() > 0 checks with isEmpty() / !isEmpty(); preserves behavior.
Logging parameterization
apollo-client/src/main/java/com/ctrip/framework/apollo/util/yaml/YamlParser.java, apollo-core/src/main/java/com/ctrip/framework/apollo/core/MetaDomainConsts.java, apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java
Replaced string concatenation / String.format in debug/warn logs with SLF4J parameterized placeholders ({}) and argument passing; no functional changes.

Sequence Diagram(s)

(Skipped — changes are small idiomatic and logging updates without new multi-component control flow.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • * Remove unused imports #111 — Modifies YamlParser.java and StringUtils.java; file-level overlap suggests related formatting/logging and isEmpty changes.

Suggested reviewers

  • hezhangjian

Poem

🐇 I hopped through code both neat and terse,
Replaced old checks with isEmpty's verse,
Logs now whisper with tidy braces,
Small hops, big smiles in refactoring places! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: refactoring string and collection checks to use idiomatic Java alternatives like isEmpty() instead of size() comparisons.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d97d1e7 and 9a20194.

📒 Files selected for processing (10)
  • apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java
  • apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java
  • apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/DefaultHttpClient.java
  • apollo-client/src/main/java/com/ctrip/framework/apollo/util/yaml/YamlParser.java
  • apollo-core/src/main/java/com/ctrip/framework/apollo/core/MetaDomainConsts.java
  • apollo-core/src/main/java/com/ctrip/framework/apollo/core/signature/Signature.java
  • apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ApolloThreadFactory.java
  • apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java
  • apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/StringUtils.java
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenPageDTO.java
✅ Files skipped from review due to trivial changes (1)
  • apollo-client/src/main/java/com/ctrip/framework/apollo/util/yaml/YamlParser.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java
  • apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/DefaultHttpClient.java
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenPageDTO.java
  • apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ApolloThreadFactory.java
  • apollo-core/src/main/java/com/ctrip/framework/apollo/core/MetaDomainConsts.java
  • apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/StringUtils.java
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2024-10-24T02:13:17.143Z
Learnt from: TerryLam2010
Repo: apolloconfig/apollo-java PR: 70
File: apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigService.java:141-144
Timestamp: 2024-10-24T02:13:17.143Z
Learning: In `apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigService.java`, when implementing the `ConfigFactory`, the method `createConfigFile(String appId, String namespace, ConfigFileFormat configFileFormat)` can return `null` as per the author's original design.

Applied to files:

  • apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java
📚 Learning: 2024-10-24T02:09:10.676Z
Learnt from: TerryLam2010
Repo: apolloconfig/apollo-java PR: 70
File: apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java:68-69
Timestamp: 2024-10-24T02:09:10.676Z
Learning: In `apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java`, it's acceptable for `ConfigUtil.getAppId()` to return `null`, and the calling code will handle `null` return values appropriately.

Applied to files:

  • apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java
📚 Learning: 2024-10-19T12:48:00.553Z
Learnt from: nobodyiam
Repo: apolloconfig/apollo-java PR: 70
File: apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RepositoryChangeListener.java:32-38
Timestamp: 2024-10-19T12:48:00.553Z
Learning: In the Apollo Java client, the class `PureApolloConfig` extends `DefaultConfig`, which implements the `onRepositoryChange(String appId, String namespace, Properties newProperties)` method from the `RepositoryChangeListener` interface. Therefore, `PureApolloConfig` doesn't need its own implementation of this method.

Applied to files:

  • apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java
📚 Learning: 2024-10-19T12:52:36.706Z
Learnt from: nobodyiam
Repo: apolloconfig/apollo-java PR: 70
File: apollo-client/src/test/java/com/ctrip/framework/apollo/spring/config/CachedCompositePropertySourceTest.java:85-85
Timestamp: 2024-10-19T12:52:36.706Z
Learning: In the Java class `ConfigChangeEvent` (`apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChangeEvent.java`), the constructor has been updated to accept three parameters: `String appId`, `String namespace`, and `Map<String, ConfigChange> changes`.

Applied to files:

  • apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (8)
🔇 Additional comments (3)
apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java (1)

68-68: LGTM! Efficient parameterized logging.

The change from string concatenation to SLF4J parameterized logging is a best practice that avoids unnecessary string construction when debug logging is disabled.

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java (1)

349-349: LGTM! More idiomatic collection check.

The change to isEmpty() is clearer and more idiomatic than size() == 0, improving code readability while maintaining identical behavior.

apollo-core/src/main/java/com/ctrip/framework/apollo/core/signature/Signature.java (1)

63-63: LGTM! More idiomatic string check.

The change to !query.isEmpty() is clearer and more idiomatic than query.length() > 0, improving code readability while maintaining identical behavior.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant