docs: add SheetsFilterViews Java sample by kencenerelli · Pull Request #1747 · googleworkspace/java-samples · GitHub
Skip to content

docs: add SheetsFilterViews Java sample#1747

Merged
PierrickVoulet merged 4 commits into
mainfrom
kencenerelli-patch-1
Feb 17, 2026
Merged

docs: add SheetsFilterViews Java sample#1747
PierrickVoulet merged 4 commits into
mainfrom
kencenerelli-patch-1

Conversation

@kencenerelli

Copy link
Copy Markdown
Contributor

Adds Java sample for filter views. Based on the sheets_filter_views sample from Python.

Description

This sample demonstrates how to:

  • Create a filter view using AddFilterViewRequest.
  • Duplicate a filter view using DuplicateFilterViewRequest.
  • Update filter criteria and titles using UpdateFilterViewRequest.

Fixes # (issue)

Is it been tested?

  • Development testing done

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have performed a peer-reviewed with team member(s)
  • I have commented my code, particularly in hard-to-understand areas
  • [x ] I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Adds Java sample for filter views.  Based on the `sheets_filter_views` sample from Python.
@gemini-code-assist

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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 adds a new Java sample for Sheets Filter Views. However, the new file contains critical syntax errors as it appears to be a direct translation from a Python sample, using Python-style comments and docstrings in a Java file. This will prevent the code from compiling. Additionally, there are some redundant code region tags and a lack of robust error handling for API responses, which could lead to runtime exceptions. My review includes suggestions to correct these issues to make the sample valid and robust.

Comment on lines +1 to +17
"""
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

# [START sheets_filter_views]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

This file contains Python-style syntax that will cause compilation errors in Java. The file header (lines 1-15) uses a Python docstring ("""...""") instead of a Java block comment (/* ... */), and the region tag on line 17 uses a Python comment character (#) instead of //.

/*
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// [START sheets_filter_views]

}
}

# [END sheets_filter_views]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

This line uses a Python-style comment (#) which is a syntax error in Java. Please use // for single-line comments.

Suggested change
# [END sheets_filter_views]
// [END sheets_filter_views]

Comment on lines +40 to +42
// [START sheets_filter_views]
filterViews("1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k");
// [END sheets_filter_views]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

These [START ...] and [END ...] region tags appear to be redundant. The entire file content relevant to the sample is already wrapped in sheets_filter_views region tags (on lines 17 and 152, though they currently have incorrect syntax). Having nested tags for the same region can cause issues with sample processing tools. Please remove these inner tags.

        filterViews("1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k");

Comment on lines +100 to +101
int filterId = response1.getReplies().get(0)
.getAddFilterView().getFilter().getFilterViewId();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The code directly accesses nested properties of the API responses (response1 on this line, and response2 on line 115) without any validation. If an API call doesn't return the expected structure (e.g., due to an error or an empty list of replies), this will cause a NullPointerException or IndexOutOfBoundsException at runtime. You should add checks to ensure the response objects and lists are not null or empty before accessing them.

@kencenerelli kencenerelli left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed malformed commenting.

Added error handling for Add and Duplicate Filter View requests to ensure valid responses.
Updated copyright year from 2022 to 2026.
@kencenerelli

Copy link
Copy Markdown
Contributor Author

@PierrickVoulet PierrickVoulet merged commit 19db17d into main Feb 17, 2026
10 of 14 checks passed
@PierrickVoulet PierrickVoulet deleted the kencenerelli-patch-1 branch February 17, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants