Recent Notes

Displaying keyword search results 1 - 10
Created by nogeek on December 30, 2011 13:54:04    Last update: December 30, 2011 13:54:04
Tomcat 7.0 failed with a SEVERE error without printing a stack trace: Dec 30, 2011 1:21:09 PM org.apache.catalina.core.S... Now it's hard to figure out what's wrong without knowing where things went wrong. Why is Tomcat not logging anything? Tomcat logging is configured by class loader. Logging behaves differently depending on which class loader loaded the logger. You'll need to look at both $CATALINA_BASE/conf/logging.properties and WEB-INF/classes/logging.properties to figure out why the stack trace is not logged. In my case, the web app specific WEB-INF/classes/logging.properties overshadowed the system $CATALINA_BASE/conf/logging.properties and suppressed the stack trace.
Created by Dr. Xi on July 11, 2011 12:24:10    Last update: July 11, 2011 12:25:44
This code snippet import java.util.*; public class UncheckedCast ... fails with a compilation error and a warning: $ javac -Xlint:unchecked UncheckedCast.java Unc... Because List<String> is not a reifiable type, the Java Runtime does not have enough information to verify the type or do the type casting. This is fixed by changing List<String> to List<?> (or to the raw type List ): public static void main(String[] args) { Ob...
Created by alfa on May 26, 2011 13:23:30    Last update: May 26, 2011 13:23:30
The operator instanceof returns true if the first operand is an instance of the second operand: if (a instanceof A) { // true if a is an in... If the above is true, then this is also true: A.class.isAssignableFrom(a.getClass()); The only difference is, the second operand to instanceof is the symbol for a class, not a class object: // This is OK if (a instanceof A) { Syst...
Created by alfa on April 08, 2011 12:33:08    Last update: April 08, 2011 12:33:08
This example captures the screen of the current Java application window, instead of the full screen. import java.io.*; import java.awt.*; import ...
Created by Dr. Xi on March 29, 2011 16:06:57    Last update: April 01, 2011 12:33:52
This utility class retrieves SSL certificates from the server and print them out to the stdout. The output can be saved to a file and imported to a Java keystore. This is useful in your test environment where the SSL certificate is self-signed. import java.io.InputStream; import java.io.Outp... Retrieve and import the a certificate: E:\test>java RetrieveSSLCert 192.168.69.144 8081 >...
Created by Dr. Xi on March 02, 2011 11:39:18    Last update: March 09, 2011 12:19:30
Some peculiarities about Java PrintWriter: PrintWriter never throws any exceptions. From JavaDoc : Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError(). When error occurs, you'll never know anything more than that it occured, because checkError returns boolean. When a character is out of the range of the character encoding of the PrintWriter, it prints a question mark (?). But this is not an error. Test code: import java.io.*; public class TestPrintWri... Latin1 test result: java TestPrintWriter iso-8859-1 | od -bc 000000... UTF-8 test result: java TestPrintWriter utf-8 | od -bc 0000000 141... Also, the constructor throws a FileNotFoundException when you try to write to a...
Created by nogeek on February 03, 2011 13:08:38    Last update: February 03, 2011 13:14:10
The log line was like this: 2011-01-19 15:16:34,842 INFO [STDOUT] (HDScanne... Note that INFO and timestamp were printed twice. Based on my configuration, I was expecting something like this: 2011-01-19 15:16:34,842 INFO [XmlWebApplicationC... i.e., the logger name should have been XmlWebApplicationContext , not STDOUT ! What was the problem? I found this error message in server.log : 2011-01-19 14:34:38,107 ERROR [STDERR] (main) lo... It turned out that org.apache.log4j.Appender was loaded by my web application class loader, whereas org.jboss.logging.appender.FileAppender was loaded by the JBoss bootstrap class loader. Removing the log4j jar from my web application archive fixed the problem (sine log4j is already available in JBoss). Why was the logger changed to STDOUT? JBoss detects that there's a problem with the log4j configuration and routes all...
Created by Fang on July 17, 2010 03:16:53    Last update: July 17, 2010 03:18:25
This error happens when the ordering of elements in web.xml is not correct. For example, in a <servlet> declaration, <servlet-name> should come before <servlet-class> . If you switch the order of <servlet-name> and <servlet-class> , you'll get this error. This was my stack trace in JBoss when I declared <load-on-startup> before <init-param> for a servlet: DEPLOYMENTS IN ERROR: Deployment "vfszip:/C:/...
Created by Dr. Xi on June 18, 2010 15:43:27    Last update: June 20, 2010 13:59:57
I got this error while starting jboss-5.1.0.GA on Solaris (there were no problems on Windows XP or Linux). 18:20:57,405 ERROR [AbstractKernelController] Er... It turned out that this was a bug in jboss-5.1.0.GA and was fixed in jboss 6. The fix was to add class="java.io.File" to conf/bootstrap/profile.xml : <bean name="AttachmentStore" class="org.jb...
Created by Dr. Xi on February 09, 2009 23:14:15    Last update: February 09, 2009 23:14:15
This example demonstrates the general steps in creating a custom Java class loader. Normally a class loader would consult its parent class loader when asked to load a class. If it's not loaded by the parent class loader, then the class loader would try to load the class on its own. This class loader tries to load the requested class on its own first, and delegates to the parent only when a java.lang.SecurityException is thrown (which happens when it tries to load core Java classes such as java.lang.String ). The classes are loaded from CLASSPATH through the getResourceAsStream call. It's important to note that when a class is loaded with a certain class loader, all classes referenced from that class are also loaded through the...