Copilot commented on code in PR #12911: URL: https://github.com/apache/ignite/pull/12911#discussion_r3009024147
########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CacheWithInterceptorIntegrationTest.java: ########## @@ -0,0 +1,212 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.ignite.internal.processors.query.calcite.integration; + +import java.util.Collection; +import java.util.List; +import javax.cache.Cache; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.cache.CacheInterceptorAdapter; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.SqlConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.jetbrains.annotations.Nullable; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; + +/** Cache interceptor related tests. */ +@RunWith(Parameterized.class) +public class CacheWithInterceptorIntegrationTest extends GridCommonAbstractTest { + /** Node role. */ + @Parameterized.Parameter(0) + public boolean keepBinary; + + /** */ + @Parameterized.Parameters(name = "keepBinary={0}") + public static Collection<?> parameters() { + return List.of(true, true); Review Comment: `parameters()` returns `List.of(true, true)`, so the test runs twice with the same `keepBinary=true` setting and never exercises `keepBinary=false`. This reduces coverage and can hide regressions in the non-keep-binary path; return both boolean values instead. ```suggestion return List.of(true, false); ``` ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java: ########## @@ -504,6 +504,28 @@ public void active(boolean active) { return new GridCacheProxyImpl<>(this.ctx, this, opCtx); } + /** @return New internal cache instance based on this one, but with application attributes. */ + @Override public GridCacheProxyImpl<K, V> withApplicationAttributes(Map<String, String> attrs) { + CacheOperationContext opCtx = this.ctx.operationContextPerCall(); + + if (opCtx == null) { + opCtx = new CacheOperationContext( + false, + false, + false, + null, + false, + null, + false, + null, + attrs); Review Comment: `GridCacheAdapter.withApplicationAttributes` passes `attrs` directly into `CacheOperationContext` when `opCtx == null`. This does not defensively copy the map, so later mutations of `attrs` can leak into the operation context. Consider copying here (or ensure `CacheOperationContext` itself always copies) to match the behavior of `CacheOperationContext#setApplicationAttributes` used by `GridCacheProxyImpl`. ```suggestion attrs != null ? new HashMap<>(attrs) : null); ``` ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java: ########## @@ -181,6 +181,24 @@ public boolean skipReadThrough() { return skipReadThrough; } + /** + * See {@link IgniteInternalCache#withApplicationAttributes(Map)}. + * + * @return New instance of CacheOperationContext with new application attributes. + */ + public CacheOperationContext withApplicationAttributes(Map<String, String> attrs) { + return new CacheOperationContext( + skipStore, + skipReadThrough, + keepBinary, + expiryPlc, + noRetries, + dataCenterId, + recovery, + readRepairStrategy, + attrs); + } Review Comment: `CacheOperationContext.withApplicationAttributes` stores the provided `attrs` map by reference. Since `SessionContextImpl` also stores attributes by reference, this can allow later external mutation of the map to affect cache operation context unexpectedly (and potentially across threads). Consider copying defensively (e.g., align with `setApplicationAttributes` which uses `new HashMap<>(...)`). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
