Skip to content

Commit

Permalink
Use Class#asSubclass in JavaConfigGui to check class before its const…
Browse files Browse the repository at this point in the history
…ructor is called
  • Loading branch information
vlsi committed Oct 18, 2020
1 parent 6587c45 commit 3a512c6
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ public void stateChanged(ChangeEvent evt) {
private void configureClassName() {
String className = classNameLabeledChoice.getText().trim();
try {
JavaSamplerClient client = (JavaSamplerClient) Class.forName(className, true,
Thread.currentThread().getContextClassLoader()).getDeclaredConstructor().newInstance();
JavaSamplerClient client = Class.forName(className, true,
Thread.currentThread().getContextClassLoader())
.asSubclass(JavaSamplerClient.class)
.getDeclaredConstructor().newInstance();

Arguments currArgs = new Arguments();
argsPanel.modifyTestElement(currArgs);
Expand Down Expand Up @@ -267,8 +269,10 @@ public void configure(TestElement config) {
*/
private boolean classOk(String className) {
try {
JavaSamplerClient client = (JavaSamplerClient) Class.forName(className, true,
Thread.currentThread().getContextClassLoader()).getDeclaredConstructor().newInstance();
JavaSamplerClient client = Class.forName(className, true,
Thread.currentThread().getContextClassLoader())
.asSubclass(JavaSamplerClient.class)
.getDeclaredConstructor().newInstance();
// Just to use client
return client != null;
} catch (Exception ex) {
Expand Down

0 comments on commit 3a512c6

Please sign in to comment.