Skip to content

chore: port changes in google-cloud-java since 2026-03-24#4170

Open
diegomarquezp wants to merge 10 commits intomainfrom
reverse-backport-monorepo-changes
Open

chore: port changes in google-cloud-java since 2026-03-24#4170
diegomarquezp wants to merge 10 commits intomainfrom
reverse-backport-monorepo-changes

Conversation

@diegomarquezp
Copy link
Copy Markdown
Contributor

@diegomarquezp diegomarquezp commented Apr 8, 2026

This PR contains the changes backported from the google-cloud-java monorepo (sdk-platform-java directory) to this standalone repository.
Included Commits Range:

  • From: googleapis/google-cloud-java@92f300a
  • To: googleapis/google-cloud-java@91eb471
    Manual Resolutions & Rejected Changes:
  • README.md: Ignored changes relating to renaming/redirection to keep this repo's state.
  • Versions: All versions for gapic-generator-java, gax, api-common, and google-cloud-shared-dependencies have been kept at (or reverted to) the original snapshot versions existing in this repo before the patch (e.g., 2.68.1-SNAPSHOT for gapic-generator-java).
  • .cloudbuild/library_generation/library_generation.Dockerfile:
    • Adjusted paths to remove sdk-platform-java/ prefix in mvn commands.
    • Fixed COPY --from=ggj-build to use correct path in old-sdk.

@product-auto-label product-auto-label bot added the size: xl Pull request size is extra large. label Apr 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances observability and resource name extraction by introducing heuristic-based canonical name extraction and a composite tracing architecture with a new LoggingTracer for actionable error reporting. It also enables trace context propagation and response size recording across gRPC and HTTP/JSON transports. Review feedback identifies several performance optimization opportunities, such as pre-compiling regular expressions and using Set for lookups, alongside correctness improvements like recursive exception unwrapping and defensive null checks.

} else if (seg.kind() == SegmentKind.LITERAL) {
String value = seg.value();
// Skipping version literals such as v1, v1beta1
if (value.matches("^v\\d+[a-zA-Z0-9]*$")) {
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.

medium

The matches method compiles the regular expression every time it is called. Since this is inside a loop, it can be inefficient. It is recommended to use a pre-compiled static final Pattern for better performance.

Segment seg = segments.get(i);
if (seg.kind() == SegmentKind.LITERAL) {
String value = seg.value();
if (value.matches("^v\\d+[a-zA-Z0-9]*$")) {
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.

medium

The matches method compiles the regular expression every time it is called. It is recommended to use a pre-compiled static final Pattern for better performance.

Comment on lines +105 to +107
private static final List<String> AIP_STANDARDS_METHODS =
ImmutableList.of(
"Get", "List", "Create", "Delete", "Update", "Patch", "Insert", "AggregatedList");
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.

medium

Using a Set instead of a List for AIP_STANDARDS_METHODS would allow for more efficient lookups. Additionally, storing the strings in lowercase would simplify case-insensitive matching in isAipStandardMethod.

References
  1. Prefer ImmutableSet for constant sets of strings. (link)
  2. Use appropriate data structures for efficient lookups.

Comment on lines +1636 to +1639
if (!Pattern.compile("\\{" + httpBinding.name() + "(?:=.*?)?\\}")
.matcher(canonicalPath)
.find()) {
continue;
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.

medium

Compiling a Pattern inside a loop is inefficient. Use a simple string containment check for {name} and {name= to avoid regex overhead.

References
  1. Avoid expensive operations like regex compilation inside loops.

Comment on lines +1983 to +1985
private static boolean isAipStandardMethod(List<String> standards, String methodName) {
return standards.stream().anyMatch(standard -> standard.equalsIgnoreCase(methodName));
}
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.

medium

This method can be optimized to use a Set for O(1) lookup instead of streaming over a List.

References
  1. Use appropriate data structures for efficient lookups.

Comment on lines +156 to +161
if (t.getCause() == null || !(t instanceof UncheckedExecutionException)) {
return t;
}
return t.getCause();
}

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.

medium

The getRealCause method only unwraps a single level of UncheckedExecutionException. It is recommended to unwrap recursively using a loop to reach the actual root cause.

References
  1. Ensure root causes are correctly identified when unwrapping exceptions.

Comment on lines +103 to +122
static String sanitizeUrlFull(final String url) {
try {
java.net.URI uri = new java.net.URI(url);
String sanitizedUserInfo =
uri.getRawUserInfo() != null ? REDACTED_VALUE + ":" + REDACTED_VALUE : null;
String sanitizedQuery = redactSensitiveQueryValues(uri.getRawQuery());
java.net.URI sanitizedUri =
new java.net.URI(
uri.getScheme(),
sanitizedUserInfo,
uri.getHost(),
uri.getPort(),
uri.getRawPath(),
sanitizedQuery,
uri.getRawFragment());
return sanitizedUri.toString();
} catch (java.net.URISyntaxException | IllegalArgumentException ex) {
return "";
}
}
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.

medium

The sanitizeUrlFull method should handle null input for url to avoid a NullPointerException. Add a defensive null check.

References
  1. Add defensive null checks for fields that are initialized outside the constructor to improve robustness against incorrect usage.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
2 Security Hotspots
62.8% Coverage on New Code (required ≥ 80%)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

Quality Gate Failed Quality Gate failed for 'java_showcase_integration_tests'

Failed conditions
2 Security Hotspots
48.5% Coverage on New Code (required ≥ 80%)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@diegomarquezp diegomarquezp marked this pull request as ready for review April 8, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants