Skip to content

Commit

Permalink
Workaround error-prone record problem without warning suppression
Browse files Browse the repository at this point in the history
Warning suppression is not ideal as it may lead to suppression of more
then originally desired. Work around
google/error-prone#2713 using error-prone's
annotation-based suppression mechanism.

Note: using `@Keep` directly is not effective. Only `@Keep`-annotated
annotation seems to work.

Note 2: using this annotation isn't usually required, as parameter
validation in compact constructor usually makes error-prone happy and
avoids aforementioned issue. Use it only when needed.
  • Loading branch information
findepi committed Mar 21, 2023
1 parent 57ace68 commit 67adea7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/
package io.trino.plugin.base;

import com.google.errorprone.annotations.Keep;

/**
* An annotation to put on record parameters as a workaround to
* <a href="https://github.com/google/error-prone/issues/2713">error-prone's 2713 issue</a>.
*/
@Keep
public @interface RecordParameter {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.airlift.jmx.CacheStatsMBean;
import io.airlift.units.Duration;
import io.trino.collect.cache.EvictableCacheBuilder;
import io.trino.plugin.base.RecordParameter;
import io.trino.plugin.base.session.SessionPropertiesProvider;
import io.trino.plugin.jdbc.IdentityCacheMapping.IdentityCacheKey;
import io.trino.spi.TrinoException;
Expand Down Expand Up @@ -658,9 +659,8 @@ private static <T, V> void invalidateCache(Cache<T, V> cache, Predicate<T> filte
cache.invalidateAll(cacheKeys);
}

private record ColumnsCacheKey(IdentityCacheKey identity, Map<String, Object> sessionProperties, SchemaTableName table)
private record ColumnsCacheKey(@RecordParameter IdentityCacheKey identity, @RecordParameter Map<String, Object> sessionProperties, @RecordParameter SchemaTableName table)
{
@SuppressWarnings("UnusedVariable") // TODO: Remove once https://github.com/google/error-prone/issues/2713 is fixed
private ColumnsCacheKey
{
requireNonNull(identity, "identity is null");
Expand Down

0 comments on commit 67adea7

Please sign in to comment.