gnodet-bot commented on code in PR #28861: URL: https://github.com/apache/camel/pull/28861#discussion_r4458720814
########## core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAsyncCommitRaceTest.java: ########## @@ -0,0 +1,116 @@ +/* + * 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.camel.component.file; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Regression test for CAMEL-25778: a file consumer can route a file twice when the exchange is committed on a different + * thread. + * <p/> + * The race: the poll thread lists the directory; another thread commits (moves the file to .camel and removes it from + * the in-progress repository); the poll thread's in-progress check now passes and routes the already-moved file a + * second time. The fix adds a post-add existence check inside {@code GenericFileConsumer.isValidFile()}. Review Comment: 💡 **Nit — Javadoc class reference:** The Javadoc says `{@code GenericFileConsumer.isValidFile()}` but the TOCTOU guard is actually added as an `@Override` in `FileConsumer.isValidFile()`, not in `GenericFileConsumer`. Worth correcting to avoid confusion for future readers: ```suggestion * second time. The fix adds a post-add existence check inside {@code FileConsumer.isValidFile()}. ``` -- 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]
