Sunday, March 3, 2013

The calling method's name

The calling method's name can be simply obtained in one line:
String methodName = new Throwable().getStackTrace()[1]
        .getMethodName();
The Throwable class creates the stack trace snapshot using a native method (this functionality is implemented by JVM) and is surprisingly effective and efficient.
We are interested in the second (index [1]) stacktrace frame since the first one (index [0]) refers to the method currently being executed. The stacktrace frame also contains information like calling class's name and invoking line's number.
AFAIK this is how logging frameworks like log4j obtain the function name used by log formatters (logging patterns).

See more: http://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html

Saturday, February 27, 2010

Windows 7 & WPA2-PSK

Windows 7 seems to have problems with some of characters used in  WPA2-PSK keys (alias: WiFi Protected Access Pre-Shared Keys, or Personal Mode) — only alphanumeric characters are allowed.

Hopefully I come up with solution:
I put some "dummy" (any text) key in the configuration dialog and save my new your_profile_name. When the newly created profile is saved I can:
  1. Run netsh (window's net shell)
  2. Enter wlan to switch to wireless configuration mode
  3. Type command: set profileparameter name="your_profile_name" keyMaterial="your_strong_and_complicated_key"
  4. done :)
And reconnect to your_profile_name.