This is an automated email from the ASF dual-hosted git repository. vavrtom pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git
The following commit(s) were added to refs/heads/main by this push: new 603a940b57 QPID-8614 - [Broker-J] Deprecated reflection methods (#171) 603a940b57 is described below commit 603a940b57b3a646222620a181e9aae37ead24ac Author: Daniil Kirilyuk <daniel.kiril...@gmail.com> AuthorDate: Thu Feb 9 11:30:37 2023 +0100 QPID-8614 - [Broker-J] Deprecated reflection methods (#171) --- .../model/ConfiguredObjectCustomSerialization.java | 2 +- .../java/org/apache/qpid/server/util/UUIDs.java | 62 ---------------------- .../management/plugin/report/ReportRunner.java | 5 +- .../src/main/java/org/apache/qpid/server/Main.java | 9 ++-- .../client/property/PropertyValueFactory.java | 4 +- .../qpid/disttest/jms/QpidQueueCreatorFactory.java | 15 ++---- .../qpid/disttest/db/ResultsDbWriterTest.java | 2 +- .../apache/qpid/tests/utils/QueueAdminFactory.java | 7 ++- .../apache/qpid/tools/util/ArgumentsParser.java | 4 +- 9 files changed, 25 insertions(+), 85 deletions(-) diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectCustomSerialization.java b/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectCustomSerialization.java index 1aae0cab84..2f4dc623ea 100644 --- a/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectCustomSerialization.java +++ b/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectCustomSerialization.java @@ -189,7 +189,7 @@ public class ConfiguredObjectCustomSerialization String propertyName = methodName.startsWith("is") ? methodName.substring(2) : methodName.substring(3); propertyName = Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1); - final boolean originalAccessible = method.isAccessible(); + final boolean originalAccessible = method.canAccess(value); try { if (!originalAccessible) diff --git a/broker-core/src/main/java/org/apache/qpid/server/util/UUIDs.java b/broker-core/src/main/java/org/apache/qpid/server/util/UUIDs.java deleted file mode 100644 index b02d1cb845..0000000000 --- a/broker-core/src/main/java/org/apache/qpid/server/util/UUIDs.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * 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.qpid.server.util; - - -/** - * UUIDs - * - */ - -public final class UUIDs -{ - private UUIDs() - { - } - - public static final UUIDGen newGenerator() - { - return newGenerator(System.getProperty("qpid.uuid.generator", - NameUUIDGen.class.getName())); - } - - public static UUIDGen newGenerator(String name) - { - try - { - Class cls = Class.forName(name); - return (UUIDGen) cls.newInstance(); - } - catch (InstantiationException e) - { - throw new RuntimeException(e); - } - catch (IllegalAccessException e) - { - throw new RuntimeException(e); - } - catch (ClassNotFoundException e) - { - throw new RuntimeException(e); - } - } - -} diff --git a/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/report/ReportRunner.java b/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/report/ReportRunner.java index a33a3d6fc2..f6dd6f2aab 100644 --- a/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/report/ReportRunner.java +++ b/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/report/ReportRunner.java @@ -173,9 +173,10 @@ public class ReportRunner<T> { try { - return report.getClass().newInstance(); + return report.getClass().getDeclaredConstructor().newInstance(); } - catch (InstantiationException | IllegalAccessException e) + catch (InstantiationException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException e) { // can't happen as by definition must have public noargs constructor } diff --git a/broker/src/main/java/org/apache/qpid/server/Main.java b/broker/src/main/java/org/apache/qpid/server/Main.java index 407eea2eaf..11490212fa 100644 --- a/broker/src/main/java/org/apache/qpid/server/Main.java +++ b/broker/src/main/java/org/apache/qpid/server/Main.java @@ -23,6 +23,7 @@ package org.apache.qpid.server; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; @@ -448,11 +449,13 @@ public class Main { try { - handler = (Thread.UncaughtExceptionHandler) Class.forName(handlerClass).newInstance(); + handler = (Thread.UncaughtExceptionHandler) Class.forName(handlerClass) + .getDeclaredConstructor().newInstance(); } - catch (ClassNotFoundException | InstantiationException | IllegalAccessException | ClassCastException e) + catch (ClassNotFoundException | InstantiationException | IllegalAccessException | ClassCastException | + NoSuchMethodException | InvocationTargetException e) { - + // ignore } } diff --git a/perftests/src/main/java/org/apache/qpid/disttest/client/property/PropertyValueFactory.java b/perftests/src/main/java/org/apache/qpid/disttest/client/property/PropertyValueFactory.java index 7a6a612390..9e2f84a273 100644 --- a/perftests/src/main/java/org/apache/qpid/disttest/client/property/PropertyValueFactory.java +++ b/perftests/src/main/java/org/apache/qpid/disttest/client/property/PropertyValueFactory.java @@ -29,9 +29,9 @@ public class PropertyValueFactory { try { - return getPropertyValueClass(type).newInstance(); + return getPropertyValueClass(type).getDeclaredConstructor().newInstance(); } - catch(Exception e) + catch (Exception e) { throw new DistributedTestException("Unable to create a generator for a type:" + type, e); } diff --git a/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java b/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java index 91dde3dd43..6a9ba71f9e 100644 --- a/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java +++ b/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java @@ -20,6 +20,8 @@ package org.apache.qpid.disttest.jms; +import java.lang.reflect.InvocationTargetException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,17 +52,10 @@ public class QpidQueueCreatorFactory try { Class<? extends QueueCreator> queueCreatorClass = (Class<? extends QueueCreator>) Class.forName(queueCreatorClassName); - return queueCreatorClass.newInstance(); - } - catch (ClassNotFoundException e) - { - throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e); - } - catch (InstantiationException e) - { - throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e); + return queueCreatorClass.getDeclaredConstructor().newInstance(); } - catch (IllegalAccessException e) + catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | + InstantiationException e) { throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e); } diff --git a/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java b/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java index b86121271c..13afa556fd 100644 --- a/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java +++ b/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java @@ -128,7 +128,7 @@ public class ResultsDbWriterTest extends UnitTestBase { String driverName = (String) context.getEnvironment().get(ResultsDbWriter.DRIVER_NAME); Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(driverName); - driverClass.newInstance(); + driverClass.getDeclaredConstructor().newInstance(); String url = (String) context.getEnvironment().get(ResultsDbWriter.URL); Connection connection = DriverManager.getConnection(url); diff --git a/systests/systests-utils/src/main/java/org/apache/qpid/tests/utils/QueueAdminFactory.java b/systests/systests-utils/src/main/java/org/apache/qpid/tests/utils/QueueAdminFactory.java index 020e805ec2..393756638e 100644 --- a/systests/systests-utils/src/main/java/org/apache/qpid/tests/utils/QueueAdminFactory.java +++ b/systests/systests-utils/src/main/java/org/apache/qpid/tests/utils/QueueAdminFactory.java @@ -21,6 +21,8 @@ package org.apache.qpid.tests.utils; +import java.lang.reflect.InvocationTargetException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,9 +41,10 @@ class QueueAdminFactory { final Class<? extends QueueAdmin> queueCreatorClass = (Class<? extends QueueAdmin>) Class.forName(queueAdminClassName); - return queueCreatorClass.newInstance(); + return queueCreatorClass.getDeclaredConstructor().newInstance(); } - catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) + catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException e) { throw new BrokerAdminException(String.format("Unable to instantiate queue admin of type '%s'", queueAdminClassName), e); diff --git a/tools/src/main/java/org/apache/qpid/tools/util/ArgumentsParser.java b/tools/src/main/java/org/apache/qpid/tools/util/ArgumentsParser.java index e9c4110645..59131d67e8 100644 --- a/tools/src/main/java/org/apache/qpid/tools/util/ArgumentsParser.java +++ b/tools/src/main/java/org/apache/qpid/tools/util/ArgumentsParser.java @@ -36,7 +36,7 @@ public class ArgumentsParser T object; try { - object = pojoClass.newInstance(); + object = pojoClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { @@ -138,7 +138,7 @@ public class ArgumentsParser Object object = null; try { - object = objectClass.newInstance(); + object = objectClass.getDeclaredConstructor().newInstance(); } catch(Exception e) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org