Thursday, February 6, 2014

Check style - What is the meaning of inherit severity ?

Inherit severity indicates that, whatever is the parent severity will be applicable for a child element.

The default parent of every module is a 'checker', and default severity is 'warning'.

Look at the Checkstyle configuration file below.

<module name="Checker"> //Default Parent
  <property name="severity" value="warning"/>  //Default property of checker

  <module name="TreeWalker">
    <module name="JavadocMethod">
      <property name="severity" value="warning"/>
      <property name="suppressLoadErrors" value="true"/>
      <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="error"/>
    </module>
    <module name="JavadocType"/>
    <module name="JavadocVariable"/>
    <module name="JavadocStyle">
      <property name="checkFirstSentence" value="false"/>
 .....

</module>


Resource:
http://checkstyle.sourceforge.net/config.html#Properties




Check Style Error- cannot initialize module TreeWalker - Unable to instantiate DoubleCheckedLocking

I was trying configure my old check style configuration file with the latest check style (Eclipse Checkstyle Plugin 5.6.1.201306282206) plugin. There is no issue during the configuration but during the activation of check style, it's throwing the below error.

cannot initialize module TreeWalker - Unable to instantiate DoubleCheckedLocking

After going through forums, what I understood was 'DoubleCheckedLocking' is not supported in the latest check style plug-in, since this attribute is exists in my old check style configuration file, it was throwing an error.

To resolve this, go to check style configuration file and remove the below line.

<module name="DoubleCheckedLocking"/>

Resource:
http://sourceforge.net/p/checkstyle/bugs/682/
http://checkstyle.sourceforge.net/releasenotes.html

Wednesday, February 5, 2014

Lazy eclipse plugin/bundle state

Plug-ins that are resolved and that have a bundle activation policy of lazy will enter the Starting state. The console window may show bundle state as <<LAZY>>. This indicates a bundle in the Starting state waiting for a class access to transition to active.

If any plug-in that remains in a starting state is indicating of a plugin that is failing to use best practices of eclipse bundlee activator class.

http://wiki.eclipse.org/Lazy_Start_Bundles
http://wiki.eclipse.org/Where_Is_My_Bundle

Wednesday, January 22, 2014

Git: Changing a remote URL


https://help.github.com/articles/changing-a-remote-s-url

Example:

$ git remote -v
origin  ssh://core@1.2.3.197/data/kgit/explorer (fetch)

Currently origin is pointing to  ssh://core@1.2.3.197/data/kgit/explorer


Want to change my remote url to ssh://kondal.kolipaka@gerrit.mycompany.net:29418/explorer.git

$ git remote set-url origin ssh://kondal.kolipaka@gerrit.mycompany.net:29418/explorer.git


Check after change:

$ git remote -v

origin  ssh://kondal.kolipaka@gerrit.mycompany.net:29418/explorer.git (push)

Thursday, January 16, 2014

Java Type Erasure: Cannot perform instanceof check against parameterized type

Can we use something like this ?

public Object[] getElements(Object inputElement) {
if (inputElement instanceof List<Parameter>) {
return ((List<Parameter>) inputElement).toArray();
}
return new Object[] {};
}

No!!!!

Compiler Error message:
Cannot perform instanceof check against parameterized type List<Parameter>. Use the form List<?> instead since further generic type information will be erased at runtime


It's telling us to use List<?> more generic type rather than specific List<Parameter>.

public Object[] getElements(Object inputElement) {
if (inputElement instanceof List<?>) {
return ((List<?>) inputElement).toArray();
}
return new Object[] {};
}


Why?

In simple terms, generic types will be erased at compile time. During the type erasure process, the Java compiler erases all type parameters and replaces each with its first bound if the type parameter is bounded, or Object if the type parameter is unbounded.

It means, the .class file or generated byte code will not have any generic type information.


Below is the code after applying type erasure by compiler.

public Object[] getElements(Object inputElement) {
if (inputElement instanceof List) {
return ((List) inputElement).toArray();
}
return new Object[] {};
}


Other example from SUN docs:

public class Node<T> {

    private T data;
    private Node<T> next;

    public Node(T data, Node<T> next) }
        this.data = data;
        this.next = next;
    }

    public T getData() { return data; }
    // ...
}

Because the type parameter T is unbounded, the Java compiler replaces it with Object:

public class Node {

    private Object data;
    private Node next;

    public Node(Object data, Node next) {
        this.data = data;
        this.next = next;
    }

    public Object getData() { return data; }
    // ...
}


In the following example, the generic Node class uses a bounded type parameter:

public class Node<T extends Comparable<T>> {

    private T data;
    private Node<T> next;

    public Node(T data, Node<T> next) {
        this.data = data;
        this.next = next;
    }

    public T getData() { return data; }
    // ...
}
The Java compiler replaces the bounded type parameter T with the first bound class, Comparable:

public class Node {

    private Comparable data;
    private Node next;

    public Node(Comparable data, Node next) {
        this.data = data;
        this.next = next;
    }

    public Comparable getData() { return data; }
    // ...
}


Resources:
http://docs.oracle.com/javase/tutorial/java/generics/erasure.html

Change Eclipse theme

I am working with eclipse 4.4(Luna), someway I don't like the eclipse new theme!! might be I was so used to the old classic theme.

Eclipse provides the option to change through Preferences.

Window->Preferences->General->Appearance

In Theme drown-down list you can find 'classic' theme, Select and click on 'Apply'. You are done!




Eclipse Error: An API baseline has not been set for the current workspace.

I was getting this error, when I imported eclipse JSDT source code which i have cloned into eclipse workspace.

To resolve this issue, modify the Eclipse workspace preferences.

Windows > Preferences > Plug-in Development > API Baselines > Options > Missing API baseline
Then, change "Error" to "Ignore" in the drop down list.