There are things you can do in Java you rarely see, generally because there is no use for it. However, there are some unusual things in Java that could be surprisingly useful. Chronicle Software uses a number of different usual patterns in it’s low-level libraries most developers wouldn’t generally come across. One of them is a class that extends Throwable but isn’t an Error or an Exception. StackTrace Extends Throwable package net.openhft.chronicle.core; /** * Throwable created purely for the purposes of reporting a stack trace. * This is not an Error or an Exception and is not expected to be thrown or caught. */ public class StackTrace extends Throwable { public StackTrace() { this ( "stack trace" ); } public StackTrace(String message) { this (message, null ); } public StackTrace(String message, Throwable cause) { super (message + " on " + Thread. currentThread ().getName(), cause); } public static StackTrace forThread(Thread t) {
Thank you for the puzzle!
ReplyDeleteUnfortunately, I couldn't clearly understand the source of such behaviour. I suppose the the reason is in a way how String Constant Pool selects constants on a base of hashCode() execution. But I'm not sure.
So will wait for your solution :)
P.S. could you, please, allow comments and RSS subscription on your GitHub blog?
I read that internally String Constant Pool uses Hashtable for storing strings. So looks like equal hashCode() values isn't enough for getting puzzle effect. Also, at the first sight, external synchs on "bb" and "cC" really work on String instance wrappers not on internally char[] arrays...
DeleteSo the puzzle is really puzzle :)