Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mysterious Java application crash



Dear Greg,

having again read through the documents you mentioned I am where I was before. The application is plain Swing, there is only a single snippet of code that is using Cocoa API, and that does like the links recommend - keep the list in an NSArray and the iterate over it (Note that this codesnippet works with introspection to allow compilation on Non-MacOS X machines as well):

private static boolean kSystemMacOsX = false;
private static Class cNSMenu = null;
private static Class cNSWindow = null;
private static Class cNSApplication = null;
private static Class cNSArray = null;
private static Class cNSRect = null;
private static Method mSetMenuBarVisibleMethod = null;
private static Method mSetHasShadowMethod = null;
private static Method mSharedApplication = null;
private static Method mWindows = null;
private static Method mObjectIterator = null;
private static Method mToAWTRectangle= null;
private static Method mFrame = null;
private static Method mTitle = null;
static
{
try
{
if (System.getProperty("os.name").indexOf("Mac OS X")!=-1)
{
Class args[] = {Boolean.TYPE};
File systemPath = new File(File.separator+"System"
+File.separator+"Library"
+File.separator+"Java"
+File.separator);
URLClassLoader classLoader = new PrivilegedURLClassLoader( new URL[] {systemPath.toURL()});
cNSMenu = Class.forName("com.apple.cocoa.application.NSMenu" , true, classLoader);
cNSWindow = Class.forName("com.apple.cocoa.application.NSWindow", true, classLoader);
cNSApplication = Class.forName("com.apple.cocoa.application.NSApplication", true, classLoader);
cNSArray = Class.forName("com.apple.cocoa.foundation.NSArray", true, classLoader);
cNSRect = Class.forName("com.apple.cocoa.foundation.NSRect", true, classLoader);
mSharedApplication = cNSApplication.getDeclaredMethod("sharedApplication", new Class[]{});
mWindows = cNSApplication.getDeclaredMethod("windows", new Class[]{});
mObjectIterator = cNSArray.getDeclaredMethod("objectEnumerator", new Class[]{});
mSetMenuBarVisibleMethod = cNSMenu.getDeclaredMethod("setMenuBarVisible", args);
mSetHasShadowMethod = cNSWindow.getDeclaredMethod("setHasShadow" , args);
mTitle = cNSWindow.getDeclaredMethod("title", new Class[]{});
mToAWTRectangle = cNSRect.getDeclaredMethod("toAWTRectangle", new Class[]{});
mFrame = cNSWindow.getDeclaredMethod("frame", new Class[]{});
kSystemMacOsX = System.getProperty("os.name").indexOf("Mac OS X")!=-1;
log.info("Activating hack for OS X: " + kSystemMacOsX);
}
}
catch (Exception e)
{
log.info("Could not activate hack for OS X", e);
e.printStackTrace();
}
}
/**
* Do a lot of ugly hacks to remove the drop shadow border on a java.awt.Window
* You'd better ignore what this method is doing....
*/
public static void removeDropShadowBorder(final Window w)
{
if (kSystemMacOsX)
{
try
{
Object nsApplication = mSharedApplication.invoke(null, new Object[]{});
Object nsArray = mWindows.invoke(nsApplication, new Object[]{});
java.util.Enumeration e = (Enumeration)mObjectIterator.invoke(nsArray, new Object[]{});
while (e.hasMoreElements())
{
Object aWindow = e.nextElement();
String title = (String)mTitle.invoke(aWindow, new Object[]{});
Object nsRect = mFrame.invoke(aWindow, new Object[]{});
Rectangle rect = (Rectangle)mToAWTRectangle.invoke(nsRect, new Object[]{});
// Compare the X-Values of the windows and enforce that the title is empty.
if (title == null || title.trim().length() == 0 && rect != null && rect.x == w.getLocationOnScreen().x)
{
mSetHasShadowMethod.invoke(aWindow, new Object[]{new Boolean(false)});
}
}
}
catch (Exception e)
{
if (log.isDebugEnabled())
log.debug("Cannot remove drop shadow border from window", e);
}
}
}


So, from my point of view, this should not be able to cause the "garbage collected java ref", as we work with hard references from a Java point of view and keep references to the cocoa objects in code, but I may very well be wrong, as I do not have experience with this API.

Any help is greatly appreciated!

Florian


Greg Guerin wrote:
Florian Bruckner wrote:

We've been unable to reproduce this in our development environment for some
time, but now start to see the following on stdout before the application
is gone:

[GC 41335K->34049K(130176K), 0.0077099 secs]
ObjCJava FATAL:
jobjc_lookupObjCObject(): returning garbage collected java ref for objc
object of class NSWindow
ObjCJava Exit

Any idea what might be the cause of this?

Googling for the error message fragment: returning garbage collected java ref for objc object of class

shows this hit:
  <http://wiki.java.net/bin/view/Mac/Jobjc_lookupObjCObject>

Total time, under a minute.

  -- GG


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



--
3Kraft Software | Applications | Development
Wasagasse 26/2
1090 Vienna
Austria

Phone: +43 (0)1 920 45 49
Fax: +43 (0)1 920 45 49
Mobile: +43 (699) 102 53 901
E-Mail: email@hidden
Web: http://www.3kraft.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: mysterious Java application crash (From: Greg Guerin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.