https://bz.apache.org/bugzilla/show_bug.cgi?id=60417

            Bug ID: 60417
           Summary: autoSizeColumn(int i) swallows interrupted exception
                    and resets interrupted flag
           Product: POI
           Version: 3.16-dev
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Invoking 

org.apache.poi.ss.usermodel.Sheet.autoSizeColumn(int column)

in an interrupted thread (interrupted flag = "true") swallows the interrupted
exception and resets the interrupted flag to "false". 
Therefore further checks whether the thread was interrupted or not will fail.
This might cause some trouble.

This bug can be observed using both "HSSF" and "XSSF" workbooks (tested with
the current beta-version (3.16-beta1-20161120)).

Code example to reproduce the bug:


import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class MainClass {

        public static void main(String[] args) {

                Thread workerThread = new WorkerThread();
                workerThread.start();

                System.out.println("Main thread will go to sleep for 2
seconds...");
                try {
                        Thread.sleep(2000);
                } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        System.out.println("Main thread interrupted while
sleeping...");
                }
                System.out.println("Main thread woke up...");
                workerThread.interrupt();
                System.out.println("Interrupting worker thread...");
        }

        public static class WorkerThread extends Thread {

                private final Workbook workbook;

                public WorkerThread() {
                        // this.workbook = new XSSFWorkbook();
                        this.workbook = new HSSFWorkbook();
                }

                @Override
                public void run() {
                        Sheet sheet = this.workbook.createSheet();

                        for (int i = 0; i < 10; ++i) {
                               
sheet.createRow(i).createCell(0).setCellValue("Row " + i);
                                System.out.println("\tWorkerThread - Before
autosize: interrupted = " + this.isInterrupted());
                                sheet.autoSizeColumn(0);
                                System.out.println("\tWorkerThread - After
autosize: interrupted = " + this.isInterrupted());
                                ++i;
                                try {
                                        Thread.sleep(1000);
                                } catch (InterruptedException e) {
                                        this.interrupt();
                                        System.out.println("\tWorkerThread -
Interrupted while sleeping...");
                                }
                        }
                }
        }
}


Output:

Main thread will go to sleep for 2 seconds...
        WorkerThread - Before autosize: interrupted = false
        WorkerThread - After autosize: interrupted = false
        WorkerThread - Before autosize: interrupted = false
        WorkerThread - After autosize: interrupted = false
Main thread woke up...
Interrupting worker thread...
        WorkerThread - Interrupted while sleeping...
        WorkerThread - Before autosize: interrupted = true
        WorkerThread - After autosize: interrupted = false
        WorkerThread - Before autosize: interrupted = false
        WorkerThread - After autosize: interrupted = false
        WorkerThread - Before autosize: interrupted = false
        WorkerThread - After autosize: interrupted = false

As one can clearly see, the interrupted flag is reset when autoSizeColumn(int
i) is invoked.

The problem seems to occur somewhere deep in java.awt.font.TextLayout. Thus
it's probably out of your scope to fix "the real bug".
However, I think it's still worth to have a look at it (and to be aware of this
bug).

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to