Skip to content

Change methods that return Boolean to return boolean and correct bad …#968

Open
fallingrock wants to merge 1 commit into
meilisearch:mainfrom
fallingrock:fix-967
Open

Change methods that return Boolean to return boolean and correct bad …#968
fallingrock wants to merge 1 commit into
meilisearch:mainfrom
fallingrock:fix-967

Conversation

@fallingrock
Copy link
Copy Markdown

@fallingrock fallingrock commented May 26, 2026

Pull Request

Related issue

Fixes #967

What does this PR do?

  • Client should return primitive booleans, not object Boolean
  • Remove invalid empty string comparison from generateTenantToken

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary

This PR updates the meilisearch-java client code to improve code quality by using primitive boolean types instead of Boolean wrapper objects and correcting invalid string equality comparisons.

Changes to Client.java

Method signature change:

  • isHealthy() method now returns primitive boolean instead of Boolean

String comparison fix in generateTenantToken() method:

  • Replaces invalid empty-string comparison == "" with proper isEmpty() method call when validating the API key parameter
  • If the provided API key is null or empty, the method falls back to using the client's configured API key

Additional validation enhancements in generateTenantToken() method:

  • Validates that the resolved signing key (secret) is non-null and longer than 8 characters
  • Validates that searchRules parameter is non-null
  • Validates that apiKeyUid is non-null, non-empty, and complies with UUIDv4 format before JWT creation/encryption

Impact

These changes follow Java best practices by favoring primitive types over wrapper objects for boolean values and ensure proper string validation logic. The method behavior is maintained while improving code correctness and clarity.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

📝 Walkthrough

Walkthrough

The Meilisearch Java SDK Client class is improved with two types of changes: method return types are simplified from wrapper Boolean to primitive boolean, and tenant token generation validation is strengthened with null checks and proper string comparison.

Changes

Client method improvements

Layer / File(s) Summary
Return type improvements
src/main/java/com/meilisearch/sdk/Client.java
isHealthy() and isValidUUID() methods return primitive boolean instead of wrapper Boolean.
Tenant token generation validation
src/main/java/com/meilisearch/sdk/Client.java
API key selection corrects string comparison from reference equality (== "") to isEmpty(). Tenant token validation enforces that signing key (secret) is non-null and longer than 8 characters, searchRules is non-null, and apiKeyUid is validated for null/emptiness and UUIDv4 compliance.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through type-safe lands,
Where Boolean bows to int's demands,
String comparisons now shine so bright,
With proper checks and validation tight!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is truncated and incomplete. While it appears to reference the main changes (Boolean to boolean conversion and string comparison fixes), the ellipsis makes it unclear and vague about the actual scope of changes. Expand the title to complete the thought. A clearer option: 'Change Boolean wrapper to primitive boolean and fix string equality comparisons'
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request successfully addresses both primary requirements from issue #967: converting Boolean wrapper return types to primitive boolean in the Client class and replacing invalid string equality comparisons with proper isEmpty() validation.
Out of Scope Changes check ✅ Passed All changes in the pull request are directly aligned with the objectives in issue #967. The modifications to isHealthy() method signature and tenant token validation with proper string checks are scope-appropriate.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/com/meilisearch/sdk/Client.java (1)

513-524: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard options before dereferencing it.

generateTenantToken(..., TenantTokenOptions options) still throws NullPointerException when callers pass null, because options.getApiKey() is accessed before any validation. Default null to new TenantTokenOptions() or throw MeilisearchException here so this path stays inside the method's documented error model.

Suggested fix
 public String generateTenantToken(
         String apiKeyUid, Map<String, Object> searchRules, TenantTokenOptions options)
         throws MeilisearchException {
+    if (options == null) {
+        options = new TenantTokenOptions();
+    }
+
     // Validate all fields
     Date now = new Date();
     String secret;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/com/meilisearch/sdk/Client.java` around lines 513 - 524, The
method generateTenantToken currently dereferences options (e.g.,
options.getApiKey() and options.getExpiresAt()) before checking for null,
causing NPEs; modify generateTenantToken to first guard options by either
replacing a null with a new TenantTokenOptions() or immediately throwing a
MeilisearchException with a clear message, then continue using
options.getApiKey(), options.getExpiresAt(), secret etc.; ensure the chosen
approach preserves the method's error model and adjust any subsequent logic that
assumes options is non-null.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/com/meilisearch/sdk/Client.java`:
- Around line 261-263: Client.isHealthy() must preserve binary
compatibility—change its return type back to Boolean (or provide an overload) so
callers compiled against the old signature don't get NoSuchMethodError; in the
tenant token path, avoid dereferencing options before null-checking: update
generateTenantToken(..., TenantTokenOptions options) to first validate options
!= null (and options.getApiKey() != null) and throw a MeilisearchException with
a clear message when missing; finally, tighten isValidUUID(String) to enforce
UUID v4 (parse with UUID.fromString(...), then assert uuid.version() == 4 and
uuid.variant() == 2) and return/throw a MeilisearchException with a
uuid4-specific error when it fails.

---

Outside diff comments:
In `@src/main/java/com/meilisearch/sdk/Client.java`:
- Around line 513-524: The method generateTenantToken currently dereferences
options (e.g., options.getApiKey() and options.getExpiresAt()) before checking
for null, causing NPEs; modify generateTenantToken to first guard options by
either replacing a null with a new TenantTokenOptions() or immediately throwing
a MeilisearchException with a clear message, then continue using
options.getApiKey(), options.getExpiresAt(), secret etc.; ensure the chosen
approach preserves the method's error model and adjust any subsequent logic that
assumes options is non-null.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e11e557e-9890-469c-8102-095d80c26ae9

📥 Commits

Reviewing files that changed from the base of the PR and between acfe026 and cd8e4c6.

📒 Files selected for processing (1)
  • src/main/java/com/meilisearch/sdk/Client.java

Comment on lines +261 to 263
public boolean isHealthy() throws MeilisearchException {
return this.instanceHandler.isHealthy();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In Java, is changing a public method return type from java.lang.Booleanto primitiveboolean binary compatible for already compiled consumers?

💡 Result:

No, changing a public method's return type from the wrapper class java.lang.Boolean to the primitive type boolean is not binary compatible with already compiled consumers [1][2]. According to the Java Language Specification (JLS), the return type of a method is a fundamental part of its signature as far as the Java Virtual Machine (JVM) and binary linking are concerned [3][4][5]. When a consumer is compiled, the method signature—including the exact return type—is recorded in the consumer's bytecode [6][5]. When you change the return type: 1. The method signature in the compiled class file changes [2]. 2. The JVM, at runtime, looks for a method with the original signature (which expects a return type of java.lang.Boolean) [6][5]. 3. Since the new method signature (expecting boolean) does not match, the link fails, typically resulting in a java.lang.NoSuchMethodError when the consumer attempts to invoke the method [7][6][2]. While this change might be source compatible (if the source code of the consumer is recompiled, the compiler will handle the necessary auto-boxing or unboxing to adapt to the change), it is fundamentally binary incompatible [1][2]. Pre-existing binaries will not be able to link against the new version of the class without being recompiled [8][2].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Identify exact locations/lines referenced
echo "=== Client.java excerpts ==="
sed -n '230,290p' src/main/java/com/meilisearch/sdk/Client.java

echo "=== Client.generateTenantToken excerpts (approx lines) ==="
sed -n '480,560p' src/main/java/com/meilisearch/sdk/Client.java

echo "=== Client UUID-related methods excerpts (approx lines) ==="
sed -n '560,700p' src/main/java/com/meilisearch/sdk/Client.java

echo "=== InstanceHandler.java excerpt ==="
sed -n '1,120p' src/main/java/com/meilisearch/sdk/InstanceHandler.java

echo "=== TenantTokenOptions.java excerpt ==="
sed -n '1,120p' src/main/java/com/meilisearch/sdk/TenantTokenOptions.java

Repository: meilisearch/meilisearch-java

Length of output: 11342


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Ripgrep for isValidUUID and uuid4 message ==="
rg -n "isValidUUID|uuid4|UUID\.fromString|generateTenantToken|TenantTokenOptions" src/main/java/com/meilisearch/sdk/Client.java

echo "=== Ripgrep for apiKey null initialization in TenantTokenOptions ==="
rg -n "apiKey" src/main/java/com/meilisearch/sdk/TenantTokenOptions.java

Repository: meilisearch/meilisearch-java

Length of output: 959


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '1,120p' src/main/java/com/meilisearch/sdk/Client.java | sed -n '1,120p'

Repository: meilisearch/meilisearch-java

Length of output: 4468


Fix binary compatibility and validation gaps in tenant token + health APIs

  • Client.isHealthy() using boolean instead of Boolean is binary-incompatible for already-compiled consumers (e.g., NoSuchMethodError)—keep Boolean or treat as a breaking (major) change.
  • generateTenantToken(..., TenantTokenOptions options) dereferences options (options.getApiKey()) before any null check, so options == null yields a NullPointerException instead of a MeilisearchException.
  • The UUIDv4 requirement is not enforced: isValidUUID() only uses UUID.fromString(...) (syntax), while the error message requires uuid4 (version/variant).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/com/meilisearch/sdk/Client.java` around lines 261 - 263,
Client.isHealthy() must preserve binary compatibility—change its return type
back to Boolean (or provide an overload) so callers compiled against the old
signature don't get NoSuchMethodError; in the tenant token path, avoid
dereferencing options before null-checking: update generateTenantToken(...,
TenantTokenOptions options) to first validate options != null (and
options.getApiKey() != null) and throw a MeilisearchException with a clear
message when missing; finally, tighten isValidUUID(String) to enforce UUID v4
(parse with UUID.fromString(...), then assert uuid.version() == 4 and
uuid.variant() == 2) and return/throw a MeilisearchException with a
uuid4-specific error when it fails.

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.

Client methods that return Boolean should return primitive and various invalid string comparisons

1 participant