hdbeukel / james-core

Core module of the JAMES framework
Apache License 2.0
6 stars 5 forks source link

Check null in checkedCopy of Solution #32

Closed neokito closed 7 years ago

neokito commented 8 years ago

Hi,

In this file: https://github.com/hdbeukel/james-core/blob/master/src/main/java/org/jamesframework/core/problems/sol/Solution.java

Problem for new users:

This is a example, when the override codes are automatically generated with the IDE.

public class MCDPSolution extends Solution{
....
    @Override
    public Solution copy() {
        // TODO Auto-generated method stub
        return null;
    }

Output:

screen shot 2016-03-22 at 10 17 27

New minor check:

    @SuppressWarnings("unchecked")
    static public <T extends Solution> T checkedCopy(T solution){
        // copy solution
        Solution copy = solution.copy();
       if (copy == null)
        {
            throw new SolutionCopyException("\nDeep copy of solution of type " + solution.getClass().getSimpleName() + " failed. "
                    + "Calling copy() yields a solution with return null.\n"
                    + "- Expected cause of this type mismatch:\n"
                    + solution.getClass().getSimpleName() + " does not completly implement method copy().");
        }
        Class<?> origClass = solution.getClass();
        Class<?> copyClass = copy.getClass();
...

New output:

screen shot 2016-03-22 at 10 16 21

Regards

hdbeukel commented 8 years ago

Thanks for the suggestion. We will add this check.