3

I am trying to edit excel file using Apache POI and OPCPackage and it is not working out for me for some weird reasons. Here is the code snippet:

File file = new File(basePath, fileName);
int currentColNum=0, currentRowNum=0;
OPCPackage pkg = null;
Workbook wb = null;
if(file.exists())
    pkg = OPCPackage.open(file);
    wb = new XSSFWorkbook(pkg);
else
    wb = new XSSFWorkbook();
Sheet sheet = wb.getSheet(sheetName);
if(sheet==null)
    sheet = wb.createSheet(sheetName);
else
    currentRowNum = lastWrittenRowCol.get(sheetName).getLeft();
for(Entry<?,?> entry : map.entrySet()) {
    //some code. This code uses functions like sheet.createRow() etc.
}
FileOutputStream out = new FileOutputStream(file);
System.out.println("before write.out");  //Printed/
wb.write(out);
System.out.println("last statement");   //Not printed.
    out.close();
if(pkg!=null)
        pkg.close();

I get the following error:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGBUS (0x7) at pc=0x00002b517248dae2, pid=14557, tid=47628802967872
#
# JRE version: 7.0_25-b15
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.25-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libzip.so+0x4ae2]  newEntry+0x62
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

And this is the memory information from the log:

/proc/meminfo:
MemTotal:      5855708 kB
MemFree:       1413996 kB
Buffers:        815896 kB
Cached:        1939120 kB
SwapCached:          0 kB
Active:        2339452 kB
Inactive:      1512396 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:      5855708 kB
LowFree:       1413872 kB
SwapTotal:     5140792 kB
SwapFree:      5140792 kB
Dirty:            5556 kB
Writeback:           0 kB
AnonPages:     1096860 kB
Mapped:         112944 kB
Slab:           520072 kB
PageTables:      39008 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
CommitLimit:   8068644 kB
Committed_AS:  2106544 kB
VmallocTotal: 34359738367 kB
VmallocUsed:     51844 kB
VmallocChunk: 34359686179 kB
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     2048 kB

I am using Eclipse. Program was run with arguments -Xms512m -Xmx2048m. There is some problem with wb.write(out) because statement just before that line is printed but the next is not. (I know I should use debugger but I do not know how to plug it in in eclipse from our build system). Any help appreciated!

Aman Deep Gautam
  • 8,091
  • 21
  • 74
  • 130
  • +1 I have observed the same recently. The error occurred in Write method and corrupted the my excel file as well. – Sankumarsingh Jan 19 '14 at 20:47
  • @Sankumarsingh Yup. I have wasted so much time on this. Hope somebody helps. – Aman Deep Gautam Jan 19 '14 at 20:54
  • Pure Java code shouldn't be able to crash the JVM, so it looks like you have hit a JVM bug. Have you tried reporting it to Oracle? – Gagravarr Jan 20 '14 at 12:41
  • @Gagravarr No. I had no idea that it could have been a bug. – Aman Deep Gautam Jan 20 '14 at 13:47
  • @Gagravarr: I have observed that in case of `opcpackage` and `workbook factory`, the crash occurred, while in case of `fileInputStream` its working fine. I have observed the same in My code as well as in Aman's code both. I am not sure why it is happening. – Sankumarsingh Jan 21 '14 at 17:40
  • No Java code should be able to crash the JVM. You need to report this is a bug to Oracle, so they can fix the underlying Java Virtual Machine bug – Gagravarr Jan 21 '14 at 17:42
  • @Gagravarr Ok. Will do it by today. thanks! – Aman Deep Gautam Jan 22 '14 at 07:45
  • @AmanDeepGautam Take a look at this [question](http://stackoverflow.com/questions/11344131/jvm-crashing-while-writing-to-xlsx-file-poi/17329250#17329250) – Jonathan Drapeau Feb 04 '14 at 18:25

1 Answers1

0

As the XSSF manipulate the Open XML format, writing it requires manipulation of an archive (zip) .. There are bug in the jzlib ..

Kindly check this fix JVM crashes at libzip.so

I hope this could help!

Community
  • 1
  • 1
Muhammad Hamed
  • 1,229
  • 9
  • 19