yashmayya commented on code in PR #14304: URL: https://github.com/apache/kafka/pull/14304#discussion_r1312896811
########## connect/runtime/src/main/java/org/apache/kafka/connect/util/ConcreteSubClassValidator.java: ########## @@ -0,0 +1,68 @@ +/* + * 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.kafka.connect.util; + +import org.apache.kafka.common.config.ConfigDef; +import org.apache.kafka.common.config.ConfigException; +import org.apache.kafka.common.utils.Utils; + +import java.lang.reflect.Modifier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class ConcreteSubClassValidator implements ConfigDef.Validator { + private final Class<?> expectedSuperClass; + + private ConcreteSubClassValidator(Class<?> expectedSuperClass) { + this.expectedSuperClass = expectedSuperClass; + } + + public static ConcreteSubClassValidator forSuperClass(Class<?> expectedSuperClass) { + return new ConcreteSubClassValidator(expectedSuperClass); + } + + @Override + public void ensureValid(String name, Object value) { + if (value == null) { + // The value will be null if the class couldn't be found; no point in performing follow-up validation + return; + } Review Comment: > I guess this can cause false positives (like the ones that we avoid with null checks in this PR), not sure if there's a chance for false negatives since by that point we're already guaranteed that there's at least one error reported for the property. Yeah, that makes sense. > This is probably worth looking into. Do you think it makes sense to file a Jira ticket and do that work as a follow-up, or should we block the PR on it Jira ticket and follow-up sounds good to me, I don't think it's worth blocking this PR on that since it's existing behavior across the board and we're handling it appropriately here anyway 👍 ########## connect/runtime/src/main/java/org/apache/kafka/connect/util/ConcreteSubClassValidator.java: ########## @@ -0,0 +1,68 @@ +/* + * 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.kafka.connect.util; + +import org.apache.kafka.common.config.ConfigDef; +import org.apache.kafka.common.config.ConfigException; +import org.apache.kafka.common.utils.Utils; + +import java.lang.reflect.Modifier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class ConcreteSubClassValidator implements ConfigDef.Validator { + private final Class<?> expectedSuperClass; + + private ConcreteSubClassValidator(Class<?> expectedSuperClass) { + this.expectedSuperClass = expectedSuperClass; + } + + public static ConcreteSubClassValidator forSuperClass(Class<?> expectedSuperClass) { + return new ConcreteSubClassValidator(expectedSuperClass); + } + + @Override + public void ensureValid(String name, Object value) { + if (value == null) { + // The value will be null if the class couldn't be found; no point in performing follow-up validation + return; + } Review Comment: > I guess this can cause false positives (like the ones that we avoid with null checks in this PR), not sure if there's a chance for false negatives since by that point we're already guaranteed that there's at least one error reported for the property. Yeah, that makes sense. > This is probably worth looking into. Do you think it makes sense to file a Jira ticket and do that work as a follow-up, or should we block the PR on it Jira ticket and follow-up sounds good to me, I don't think it's worth blocking this PR on that since it's existing behavior across the board and we're handling it appropriately here anyway 👍 -- 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]
