Bug 130735

Summary: Importing java files that reference their own class name (eg. singleton objects) crashes umbrello
Product: [Applications] umbrello Reporter: Clinton Grant <clintgr>
Component: generalAssignee: Oliver Kellogg <okellogg>
Status: RESOLVED WORKSFORME    
Severity: crash    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In:

Description Clinton Grant 2006-07-13 05:32:18 UTC
Version:           1.5.3 (using KDE KDE 3.5.3)
Installed from:    Fedora RPMs
Compiler:          gcc 4.1.1 
OS:                Linux

I have patched my version of the source to include the changes in 1.5.4 for java import issues.

However, if you import this code umbrello will crash:

public class TestClass
{

	public TestClass getInstance ()
	{
		return instance;
	}

	private TestClass()
	{
	}
	
	public void SomeMethod()
	{
	}

	String aString;
	String anotherString; 
	TestClass instance = new TestClass();
	
}


I debugged the crash, and it can be prevented with this change:

@@ -286,7 +286,7 @@
     }
     QString typeName = joinTypename();
     QString name;
-    if ( (typeName == m_klass->getName())) {
+    if ((m_klass != NULL) && (typeName == m_klass->getName())) {
         // Constructor.
         name = typeName;
         typeName = QString::null;

If this is done, the import still doesn't work because the importer gets confused over the getInstance method and instance member. This appears to be because the class is referencing instances of itself.
Comment 1 Oliver Kellogg 2006-07-16 01:17:38 UTC
SVN commit 562838 by okellogg:

parseStmt(): Check for m_klass being NULL before dereferencing it.
Thanks to Clinton Grant for spotting this.
CCBUG:130735


 M  +1 -1      javaimport.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/javaimport.cpp #562837:562838
@@ -286,7 +286,7 @@
     }
     QString typeName = joinTypename();
     QString name;
-    if (typeName == m_klass->getName()) {
+    if (m_klass != NULL && typeName == m_klass->getName()) {
         // Constructor.
         name = typeName;
         typeName = QString::null;
Comment 2 Oliver Kellogg 2006-07-16 09:22:41 UTC
Works for me now, probably due to commit 562848 (see bug 130792)