PrintWriter and PrintStream never throw IOExceptions

I think that since System.out and System.err are instances of PrintStream, some more relaxed error handling was provided. This was probably, as other posters have mentioned, to smooth the way for those transitioning from C/C++ circa 1995. When the Reader/Writer API was added, PrintWriter was created to parallel the existing PrintStream. One application where this … Read more

java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session

The problem is that you have hibernate-core-4.0.0.Final.jar in your classpath, but Spring 3.1 uses hibernate-core-3.6.0.Final.jar (see here Spring 3.1 artifact and dependencies). Remove Hibernate 4.0 and put Hibernate 3.6 instead in your classpath. BTW, there might some more such miss matches. It’s better to use maven to take care of dependencies. EDIT – some more … Read more

What is the best way to avoid NoSuchElementException in Selenium?

You can never be sure that element will be found, actually this is purpose of functional tests – to tell you if anything changed on your page. But one thing which definitely helps is to add waits for the elements which are often causing NoSuchElementException like WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

Spring: Standard Logging aspect (interceptor)

Yes there are! <bean id=”customizableTraceInterceptor” class=”org.springframework.aop.interceptor.CustomizableTraceInterceptor”> <property name=”enterMessage” value=”Entering $[methodName]($[arguments])”/> <property name=”exitMessage” value=”Leaving $[methodName](): $[returnValue]”/> </bean> <aop:config> <aop:advisor advice-ref=”customizableTraceInterceptor” pointcut=”execution(public * BankAccountServlet.*(..))”/> </aop:config> Check out the CustomizableTraceInterceptor API, you can define separate enter/exit/exception messages with several placeholders: $[methodName] – replaced with the name of the method being invoked $[targetClassName] – replaced with the name of … Read more

Tomcat 7.0.73 doesn’t work with java 9

You’ll have to hack the script bin/catalina.sh to get this to work. There are a bunch of lines like this in bin/catalina.sh: exec “$_RUNJDB” “$LOGGING_CONFIG” $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs=”$JAVA_ENDORSED_DIRS” -classpath “$CLASSPATH” \ … Just remove the second of those lines (the one with -Djava.endorsed.dirs) in each case and you should be back in business. … Read more