Skip to content

Commit

Permalink
Fixes the clone method of the state reporter (#43) (#44)
Browse files Browse the repository at this point in the history
* Fixes the clone method of the state reporter (#43)

Since the cloned object may reside in a different class loader,
we need to use the Theme class from the given class loader instead
of the class from our own class loader.

Co-authored-by: Andre Wachsmuth <awa@xima.de>

* Update project version

---------

Co-authored-by: Andre Wachsmuth <sensenmann5@gmail.com>
Co-authored-by: Andre Wachsmuth <awa@xima.de>
  • Loading branch information
3 people authored May 14, 2023
1 parent c5f1ee1 commit 8905546
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Configure your POM like the following
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</dependency>
</dependencies>
<configuration>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<packaging>jar</packaging>

<name>maven-surefire-junit5-tree-reporter</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public Object clone(ClassLoader target) {
Object clone = super.clone(target);

Class<?> cls = clone.getClass();

Class<?> themeClass = target.loadClass(Theme.class.getName());
@SuppressWarnings({ "rawtypes", "unchecked" })
Object clonedTheme = Enum.valueOf((Class) themeClass, getTheme().name());

cls.getMethod("setPrintStacktraceOnError", boolean.class).invoke(clone, isPrintStacktraceOnError());
cls.getMethod("setPrintStacktraceOnFailure", boolean.class).invoke(clone, isPrintStacktraceOnFailure());
cls.getMethod("setPrintStderrOnError", boolean.class).invoke(clone, isPrintStderrOnError());
Expand All @@ -43,11 +48,11 @@ public Object clone(ClassLoader target) {
cls.getMethod("setPrintStdoutOnError", boolean.class).invoke(clone, isPrintStdoutOnError());
cls.getMethod("setPrintStdoutOnFailure", boolean.class).invoke(clone, isPrintStdoutOnFailure());
cls.getMethod("setPrintStdoutOnSuccess", boolean.class).invoke(clone, isPrintStdoutOnSuccess());
cls.getMethod("setTheme", Theme.class).invoke(clone, getTheme());
cls.getMethod("setTheme", themeClass).invoke(clone, clonedTheme);

return clone;
} catch (ReflectiveOperationException e) {
throw new IllegalStateException(e.getLocalizedMessage());
throw new IllegalStateException(e.getLocalizedMessage(), e);
}
}

Expand Down

0 comments on commit 8905546

Please sign in to comment.