JDK-7022845 : Access violation in DnD : A thread which uses COM must call CoInitializeEx() or OleInitialize()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0u22
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2011-02-28
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0u22Resolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
A CU faces with process crash(access violation) during DnD operation.

The access violation occurs at ole32.dll  called from CoLockObjectExternal()
in AwtComponent::DestroyDropTarget().

There seems a bug in AWT source code in jdk5ux.

INVESTIGATION:
According to the MS docimentation, a thread which calls COM functions must call
CoInitializeEx() or OleInitialize() in order to initialize COM before calling the COM functions.

In jdk5u22, OleInitialize() is called in the following portion of source code.
This is done  in "AWT-Windows" thread.

--- j2se/src/windows/native/sun/windows/awt_DnDDT.cpp (jdk5u22)----
1208 void awt_dnd_initialize() {
1209     ::OleInitialize((LPVOID)NULL);
1210 }
-------------------------------------------

On the other hands, AwtComponent::DestroyDropTarget() and AwtComponent::CreateDropTarget()
which actually call COM functions, are executed in "AWT-EventQueue-0" or user thread
of java.awt.dnd.DropTarget.

In other words, the thread which actually uses COM(calls COM functions) does not initialize COM, 
which is, does not call CoInitializeEx() or OleInitialize() .

This seems to go against the following statement (guideline) in Remarks seciton of [3].
"CoInitializeEx must be called at least once, and is usually called only once, for each thread that uses the COM library."

NOTE:
MS documentations

[1] OleInitialize():
http://msdn.microsoft.com/en-us/library/ms690134(v=vs.85).aspx
[2] CoLockObjectExternal():
http://msdn.microsoft.com/en-us/library/ms680592(v=vs.85).aspx
[3] CoInitializeEx():
http://msdn.microsoft.com/en-us/library/ms695279(v=vs.85).aspx

Comments
EVALUATION The fix for the problem has been delivered for CR 6407026 in jdk7.
28-02-2011