Bug 6903

Summary: 1GOMQ6H:- NullPointerException when exporting to a jar
Product: [Eclipse Project] JDT Reporter: OTI Support <support>
Component: UIAssignee: Dani Megert <daniel_megert>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P1    
Version: 1.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
contains 2 .class files and 1 .java file none

Description OTI Support CLA 2001-12-13 14:16:02 EST
When creating a jar with .class and .java files, WSWB generates an Null pointer 
exception.

Steps to reproduce problem:

1. create a java project named "bug1"
2. extract the attached bug.jar to some temporary directory.
3. copy the java file Person.java and class files Person.class and 
Person_Pickler_Vj.class to the project "bug1" directory.  select the bug1 
project, and do a refresh from local.
4. do File/Export/Jar on project bug1, you should be able to get a 
NullPointerException.
p.s. Note that Person_Pickler_Vj.class is IMPORTANT. This class file 
does not have corresponding source file.
Comment 1 OTI Support CLA 2001-12-13 14:17:02 EST
Created attachment 171 [details]
contains 2 .class files and 1 .java file
Comment 2 Olivier Thomann CLA 2001-12-13 15:01:39 EST
The stack trace I get is:
Log: Thu Dec 13 15:01:21 EST 2001
4 org.eclipse.core.resources 368 Resource /P does not exist.
Log: Thu Dec 13 15:04:45 EST 2001
4 org.eclipse.jdt.ui 1 Internal Error
java.lang.reflect.InvocationTargetException: java.lang.NullPointerException
at java.lang.String.<init>(String.java:210)
at 
org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.buildJavaToClassM
ap(JarFileExportOperation.java:391)
at 
org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.filesOnClasspath(
JarFileExportOperation.java:316)
at 
org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.exportElement(Jar
FileExportOperation.java:210)
at 
org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.exportSelectedEle
ments(JarFileExportOperation.java:282)
	at 
org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.singleRun(JarFile
ExportOperation.java:520)
	at 
org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation.run(JarFileExport
Operation.java:502)
	at 
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.jav
a:98)

The problem seems to be that inside JarFileExportOperation::buildJavaToClassMap 
method a call to sourceFileName()is done(String javaName= new 
String(cfReader.sourceFileName());). The method sourceFileName can return null. 
See the API on ClassFileReader:
/**
 * (c)1998 Object Technology International.
 * (c)1998 International Business Machines Corporation.
 *
 * Answer the source file name attribute. Return null if there is no source file 
attribute for the receiver.
 * 
 * @return char[]
 */
public char[] sourceFileName() {
	return this.sourceFileName;
}

And the null case is not handled properly. Suggest move to JDTUI.
Comment 3 Dani Megert CLA 2001-12-14 08:23:46 EST
I fixed the bug but most likely the result will not be the expected one i.e. the
  offending class file will not be packaged.

How did this file go into the build directory? How generated it?If you have
class files which are already there, I suggest to put them into a so-called
class folder. This is supported by the JAR file exporter.
Available in builds > 20011213