This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 118666 - imageio call never returns while running under netbeans (jdk1.6x)
Summary: imageio call never returns while running under netbeans (jdk1.6x)
Status: VERIFIED INCOMPLETE
Alias: None
Product: platform
Classification: Unclassified
Component: Execution (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-12 08:49 UTC by annamoto
Modified: 2011-08-10 18:08 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description annamoto 2007-10-12 08:49:28 UTC
Hi,
i found something strange while running code bellow under netbeans ide (run, or debug mode). (This is a dirty loop, 
that's for example). I don't know exactly if this is the right place, but it's netbeans related.

while running under netbeans with jdk1.5xxx it runs fine.
while running under netbeans with jdk1.6xxx the imageio call never returns and blocks.
finally, if i launch the netbeans compiled jar (jdk1.6x) application, from a command line, using jdk1.6xxx it runs!
so i think this is not a jdk bug but a netbeans one.

Yann

Product Version: NetBeans IDE 6.0 Beta 1 (Build 200709141330) 
Java: 1.6.0; Java HotSpot(TM) Client VM 1.6.0-b105 
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb) 
Userdir: C:\Documents and Settings\yhe\.netbeans\6.0beta1

public class Main {
    public static void main(String[] args) {
        CWorkerThread lCWorkerThread = new CWorkerThread();
        lCWorkerThread.start();

        java.io.InputStreamReader lInputStreamReader = new java.io.InputStreamReader(java.lang.System.in);
        java.io.BufferedReader lBufferedReader = new java.io.BufferedReader(lInputStreamReader);
        try {
            java.lang.System.out.println("Any key to stop.");
            lBufferedReader.readLine();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
        
        CWorkerThread.isRunning = false;
        lCWorkerThread.interrupt();
        
        System.out.println("work done");
    }
}
public class CWorkerThread extends Thread {   
    public static boolean isRunning = true;
    
    @Override
    public void run(){
        System.out.println("run");
        while (isRunning){
            try {
                System.out.println("load start");
                BufferedImage lBufferedImage = ImageIO.read(new File("/Content/img10.jpg")); // NEVER RETURNS FROM THIS
                System.out.println("load end");
            }catch(Exception ex){
                ex.printStackTrace();
            }
        }
        System.out.println("~run");
    }
}
Comment 1 Dusan Balek 2007-10-16 08:35:23 UTC
Reassigning for evaluation.
Comment 2 Petr Nejedly 2007-10-16 12:26:51 UTC
It works OK for me.
What is strange is that you reported Windows platform, yet use path like "/Content/img10.jpg", which is probably invalid
on win.
Also, there might be some difference in workdir setup of the running application, which may further influence the
ability to resolve the path.
Moreover, if the worker thread fails with some kind of error (not Exception), the thread might die silently.

Please provide a thread dump of the state where it should have returned from the read call, or try running it under
debugger. I can't reproduce the problem and can't do much about it without additional data.
Comment 3 annamoto 2007-12-26 11:20:48 UTC
hi, i'm back with additionnal informations,

problem is in ImageIO.createImageInputStream, it goes to a MemoryCacheImageInputStream constructor, this constructor 
blocks, and is different from jdk1.5. 
Under JDK1.6 it never works
Under JDK1.5 it works

here's the jdk 1.6 one :
    public MemoryCacheImageInputStream(InputStream stream) {
        if (stream == null) {
            throw new IllegalArgumentException("stream == null!");
        }        
        this.stream = stream;

        disposerRecord = new StreamDisposerRecord(cache);
        if (getClass() == MemoryCacheImageInputStream.class) {
            disposerReferent = new Object();
            Disposer.addRecord(disposerReferent, disposerRecord);
        } else {
            disposerReferent = new StreamFinalizer(this);
        }
    }

here's the 1.5 one:
    public MemoryCacheImageInputStream(InputStream stream) {
        if (stream == null) {
            throw new IllegalArgumentException("stream == null!");
        }        
        this.stream = stream;
    }

Product Version: NetBeans IDE 6.0 (Build 200711261600)
Java: 1.6.0; Java HotSpot(TM) Client VM 1.6.0-b105
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
Userdir: C:\Documents and Settings\yhe\.netbeans\6.0

public class Main {
    public static void main(String[] args) {
        CWorkerThread lCWorkerThread = new CWorkerThread();
	Thread t = new Thread(lCWorkerThread);
	t.start();

        java.io.InputStreamReader lInputStreamReader = new java.io.InputStreamReader(java.lang.System.in);
        java.io.BufferedReader lBufferedReader = new java.io.BufferedReader(lInputStreamReader);
        try {
            java.lang.System.out.println("Any key to stop.");
            lBufferedReader.readLine();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
//        lCWorkerThread.interrupt();
        
        System.out.println("work done");
    }
}
public class CWorkerThread implements Runnable {

    public void run() {
        System.out.println("run");
        try {
            System.out.println("load start");
            File lFile = new File("MYPATH TO img.jpg :) this is not a path problem");
            FileInputStream lFileInputStream = new FileInputStream(lFile);
            System.out.println("createImageInputStream start");
            ImageInputStream lImageInputStream = ImageIO.createImageInputStream(lFileInputStream); // NEVER RETURNS 
FROM THIS
            System.out.println("read start");
            BufferedImage lBufferedImage = ImageIO.read(lImageInputStream);
            System.out.println("load end");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("~run");
    }
}

Comment 4 annamoto 2007-12-26 12:20:40 UTC
Strange, when running under eclipse i got exactly the same problem.
From command line it run ok. Do we have a relation between the use of an IDE and graphics parts, Java2d... - ? -
Comment 5 Tomas Zezula 2007-12-26 12:48:39 UTC
The command line version runs also on the JDK 1.6.0-b105, right?
Can you generate full thread dump when the program is hanged? On Linux (JDK 1.6.0_05-ea-b04) seems to work fine.

Console output:
init:
deps-jar:
compile:
run:
Any key to stop.
run
load start
createImageInputStream start
read start
load end
~run
Comment 6 annamoto 2007-12-26 14:57:56 UTC
>Can you generate full thread dump when the program is hanged?

i tried to dump a netbeans console app (this netbeans console app),
surprise! i can't! 
all jdk tools freeze and never returns, no output, when i point them to the application pid.

note that if i launch the same application from netbeans and commenting the imageio call (no thread launched), 
it works fine and i can get a full useless dump!
Comment 7 Tomas Zezula 2007-12-26 16:46:03 UTC
Seems as a JVM issue (problem in allocation of safe state may cause JVM not to be able to generate thread dump), I will
try to get some Windows machine to reproduce it.
Comment 8 Antonin Nebuzelsky 2008-02-19 14:00:45 UTC
Reassigning to new module owner Tomas Holy.
Comment 9 Lukas Hasik 2008-04-10 21:22:45 UTC
moving opened issues from TM <= 6.1 to TM=Dev
Comment 10 Jesse Glick 2010-02-03 18:46:39 UTC
Likely error in either user code or JDK; assuming obsolete. Please reopen with a complete, self-contained, reproducible test case if you are still having problems and you believe NetBeans is the cause.
Comment 11 Chris03 2011-08-10 18:08:03 UTC
I ran in to this today. Below is the code to reproduce the issue.

I was also able to find what is causing the lock.
If ImageIO.read in called in a new thread and that on the main thread you called System.in.read, then ImageIO will lock... haven't found why but it has something to do with this method Disposer.addRecord



import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;

/**
 *
 * @author Administrator
 */
public class Test {

    interface Listener {

        public void perform(byte[] data);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {

        final Listener listener = new Listener() {

            @Override
            public void perform(byte[] data) {
                System.out.println("Begin");

                BufferedImage img = null;
                ByteArrayInputStream in = new ByteArrayInputStream(data);

                try {
                    img = ImageIO.read(in);
                } catch (IOException ex) {
                    System.out.println(ex);
                }

                System.out.println("End");
            }
        };

        Thread dispatcher = new Thread(new Runnable() {

            @Override
            public void run() {

                // Here we get the image data..
                byte[] imageData = new byte[1]; // Content doesn't matter

                System.out.println("Dispatching...");
                listener.perform(imageData);
            }
        }, "Dispatcher");

        dispatcher.start();

        System.out.println("Started");

        System.in.read(); // End will never be call with this

        //while (true) { // End will be called
        //    Thread.sleep(100);
        //}
    }
}