The second parameter is only used for casting. The updated log message makes sense, though. Added.
On 15 April 2014 18:53, Remko Popma <[email protected]> wrote: > Should the ClockFactory debug statement not be this? > > LOGGER.debug("Using {} for timestamps", result.getClass().getName()); > > I'm assuming that Loader.newCheckedInstanceOf returns an instance of the > 2nd param if it can't instantiate the 1st param. (Away from PC). > > Sent from my iPhone > > On Tuesday, April 15, 2014, <[email protected]> wrote: > >> Author: mattsicker >> Date: Tue Apr 15 05:55:06 2014 >> New Revision: 1587433 >> >> URL: http://svn.apache.org/r1587433 >> Log: >> Use Loader.newCheckedInstanceOf >> >> Modified: >> >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/ClockFactory.java >> >> logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java >> >> Modified: >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/ClockFactory.java >> URL: >> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/ClockFactory.java?rev=1587433&r1=1587432&r2=1587433&view=diff >> >> ============================================================================== >> --- >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/ClockFactory.java >> (original) >> +++ >> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/ClockFactory.java >> Tue Apr 15 05:55:06 2014 >> @@ -75,7 +75,7 @@ public final class ClockFactory { >> return CoarseCachedClock.instance(); >> } >> try { >> - final Clock result = (Clock) >> Class.forName(userRequest).newInstance(); >> + final Clock result = >> Loader.newCheckedInstanceOf(userRequest, Clock.class); >> LOGGER.debug("Using {} for timestamps", userRequest); >> return result; >> } catch (final Exception e) { >> >> Modified: >> logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java >> URL: >> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java?rev=1587433&r1=1587432&r2=1587433&view=diff >> >> ============================================================================== >> --- >> logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java >> (original) >> +++ >> logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java >> Tue Apr 15 05:55:06 2014 >> @@ -20,6 +20,7 @@ import java.io.FileWriter; >> import java.io.IOException; >> >> import com.lmax.disruptor.collections.Histogram; >> +import org.apache.logging.log4j.core.helpers.Loader; >> >> public class PerfTest { >> >> @@ -66,8 +67,7 @@ public class PerfTest { >> >> public void doMain(final String[] args) throws Exception { >> final String runnerClass = args[0]; >> - final IPerfTestRunner runner = (IPerfTestRunner) >> Class.forName(runnerClass) >> - .newInstance(); >> + final IPerfTestRunner runner = >> Loader.newCheckedInstanceOf(runnerClass, IPerfTestRunner.class); >> final String name = args[1]; >> final String resultFile = args.length > 2 ? args[2] : null; >> for (final String arg : args) { >> @@ -140,9 +140,12 @@ public class PerfTest { >> >> if (file != null) { >> final FileWriter writer = new FileWriter(file, true); >> - writer.write(result); >> - writer.write(System.getProperty("line.separator")); >> - writer.close(); >> + try { >> + writer.write(result); >> + writer.write(System.getProperty("line.separator")); >> + } finally { >> + writer.close(); >> + } >> } >> } >> >> >> >> -- Matt Sicker <[email protected]>
