POI 3.12 - Windows - IBM JVM

Here is some code (CopyRow is my own concoction based on some code I found on 
StackOverflow):

              try {
                     copyRow(sh, n1, n2);
                     sh.removeRow(sh.getRow(n1));
                     copyRow(sh, n2+1, n1);
                     sh.removeRow(sh.getRow(n2+1));
//                   int last = Math.min(sh.getLastRowNum(), n2+2);
//                   int last = StrictMath.min(sh.getLastRowNum(), n2+2);
                     int last = sh.getLastRowNum();
                     last = (last < n2+2 ? n2+2 : last);
                     sh.shiftRows(n2+2, last, -1);
              } catch (Exception e) {
                     e.printStackTrace();
              }

If I comment out

int last = sh.getLastRowNum();
       last = (last < n2+2 ? n2+2 : last);

and restore either of the two lines above it,

       Workbook wb = new XSSFWorkbook();

In my main method (different class) throws a NullPointerException, but the code 
as stated above works, but even so, the logic is incorrect because I was 
confused about what was happening. Now that my fog is clearing, I know how to 
fix the logic, but still remain unclear why Math.min() would cause new 
XSSFWorkbook() to throw a NullPointerError. Any ideas?

Reply via email to