docs: add SheetsFilterViews Java sample#1747
Conversation
Adds Java sample for filter views. Based on the `sheets_filter_views` sample from Python.
There was a problem hiding this comment.
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.
| """ | ||
| 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] |
There was a problem hiding this comment.
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] |
| // [START sheets_filter_views] | ||
| filterViews("1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k"); | ||
| // [END sheets_filter_views] |
There was a problem hiding this comment.
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");| int filterId = response1.getReplies().get(0) | ||
| .getAddFilterView().getFilter().getFilterViewId(); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Fixed malformed commenting.
Added error handling for Add and Duplicate Filter View requests to ensure valid responses.
Updated copyright year from 2022 to 2026.

Adds Java sample for filter views. Based on the
sheets_filter_viewssample from Python.Description
This sample demonstrates how to:
AddFilterViewRequest.DuplicateFilterViewRequest.UpdateFilterViewRequest.Fixes # (issue)
Is it been tested?
Checklist