Saturday, April 11, 2015

Should logger be private static or not

Just read -

decision is full of trade off but, that article is the best, so I am referencing it in my blog to let me quickly find it, as that question re-appear again and again.

My position:
Logger should never be public or protected and even share-able with or accessible by others classes, eventually will be enforced by Checkstyle -

Tuesday, March 24, 2015

Oracle listener is stopped unexpectedly on Xubuntu 14.04

Oracle listener is always launched on startup, I did not nothing special to stop it, but during work I found that listener is not started ....

15:01 $ lsnrctl status

LSNRCTL for Linux: Version - Production on 24-MAR-2015 15:01:40

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rivanov)(PORT=1521)))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused

15:01 $ lsnrctl start

LSNRCTL for Linux: Version - Production on 24-MAR-2015 15:12:35

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Alias                     LISTENER
Version                   TNSLSNR for Linux: Version - Production
Start Date                24-MAR-2015 15:02:20
Uptime                    0 days 0 hr. 10 min. 15 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           XE
Listener Parameter File   /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File         /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/vdu-rivanov/listener/alert/log.xml
Listening Endpoints Summary...
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XE" has 1 instance(s).
  Instance "XE", status READY, has 1 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
  Instance "XE", status READY, has 1 handler(s) for this service...
The command completed successfully

BUT SQLDeveloper still have no ability to connect to local instance.
Java still cannot connect to ORACLE XE on "mvn clean test"

15:10 $ sudo /etc/init.d/oracle-xe restart

after that command all works fine

Thursday, March 12, 2015

Neutral Filters and Evaluator ordering for Logback SMTPAppender

Example of config with nuance of NEUTRAL usage for filters,
miss of at least one filter that do deny by well distinctive parameter (level, marker) will result in sending mail with all events from begging of logs till event required in Evaluator.

<appender name="MY_MAIL" class="">


<if condition="property(&quot;MY_ENV_VAR&quot;) == &quot;&quot; || property(&quot;MY_ENV_VAR&quot;) == null">
<subject>[%marker] [%p] from ${HOSTNAME}</subject>
<subject>[${MY_ENV_VAR}] [%marker] [%p] from ${HOSTNAME}</subject>

<!-- the way SMTPAppender works makes him only apply filters firsly 
    and then apply evaluator to actually trigger 
e-mail sending, filters are also executed in order in 
which they are defined in configuration -->
<!-- Due to usage of NEUTRAL at EvaluatorFilter(see below) without 
    this filter, mail will contain all events from beggining 
    till MY_MARKER -->
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">

<!-- perform more precise filtering, 
    you can suppress particular messages here -->
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
// reduce noise of job for some problems
if (level == WARN && logger.contains("ConstraintService") 
&& message.contains("violates constraint")) {
return false;
return true;
<!-- NEUTRAL as we may want to add more filters later -->

<!-- This evaluator triggers e-mail sending. As we only filter 
    events with appropriate
marker, e-mail would always have only one logEvent -->
<evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">


Tuesday, March 10, 2015

Catch Exception or catch Throwable when you need to log anything

When you ask yourself a question what to catch in main method Exception and Throwable - use Throwable to catch all unexpected problems for sure.

if you choose to catch Exception you will lose Errors ,and Errors are not only system problems.

interesting Error that could happen in business logic + misconfiguration

initialization of non static field


declaration of Configuration

public enum Configuration {

private AbstractApplicationContext context;

private Configuration() {
this.context = new AnnotationConfigApplicationContext("com.mycompany");

public static <T> T getBean(Class<T> clazz) {
return INSTANCE.context.getBean(clazz);

public void destroy() {


If you somewhow did a mistake in from and Configuration will fail to initialize then getBean is failed with ExceptionInInitializerError, but it have a cause Exception that could be like:

Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mycompany.ExecutableImpl.execute(
at com.revere.xfeed.customclients.renaissance.MyTestClass.main(
Caused by: org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is (No such file or directory)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(

so you have to catch Thowable in main method to log all problems before exiting a application.

interface Executable {
void execute(Object args) throws Throwable;

class ExecutableImpl implements Executable {

public void doAll() throws IOException, FTPException {
throw new IOException();

public void execute(Object args) throws Throwable {
try {
} catch (Throwable th) {
throw th;


or do "throws Exception" in interface , no other changes are required,  but that will kind if lie to developers as you know that code could throw ExceptionInInitializerError :) even it mean to be RuntimeException.

Functional naming guides is not good for OOP

As you pass in parameter object - it have to be named as noun. Library method expect function. Function is a noun, so it is object.
Object Oriented languages have very good methodology for naming of all items, that let read code easily, mixing in different methodology that conflicts - it is not good approach.

-  names = FluentIterable.from(zipFiles).transformAndConcat(getTableNamesForZipFile).toSet();
+ names = FluentIterable.from(zipFiles).transformAndConcat(tableNamesForZipFileMaker).toSet();

  public <T> FluentIterable<T> transformAndConcat(
      Function<? super E, ? extends Iterable<? extends T>> function) {
    return from(Iterables.concat(transform(function)));

Name should be:
tableNamesForZipFileResolver, ...

It is ok to have no standard prefix/suffix for name, as all functions are different by type (different functional libraries).

Economizing on 2-5 letter in comparison  to use "get" prefix does not cost that.

Interesting compromise for naming function objects : column2Name, file2name, zipFile2Name

Naming patterns for filtering methods


Good naming pattern for filters as "filter" term does not not describe where required object will be - removed from collection or stay in collection:

rejectXXXXX - Inverse of filter, returning elements that do not match the predicate.

selectXXXXX - Runs a boolean function on each element and only puts those that pass into the output..

Why JavaDoc is matter in checkstyle code ?

As a mentor I do a lot of code reviews ...

My moto: Good code with good naming does not need any comment and JavaDoc

but ..... in Checkstyle we demand javadoc for all elements of class

Why we need that ?

to validate method logic I need to know author intentions

2) catch problems in naming like
     * Method makes recurse DetailAST and save types that it returns. Its an
    private void findAllMethodReturnTypes(DetailAST processingSiblingAST) {

     * Method checks if inner private defined type (class, interface or enumeration)
     * is private and does not implement(extend)
     * something, if so it adds type's name to the set of private types.......
    private void getPrivateType(DetailAST innerTypeDefAST) {

It is better for reading of newly created code.