Bug 38776 - [PATCH] Jsp generated servlet classes have bad SourceFile attribute
Summary: [PATCH] Jsp generated servlet classes have bad SourceFile attribute
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Servlet & JSP API (show other bugs)
Version: 5.5.9
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2006-02-23 23:57 UTC by Dave Brosius
Modified: 2006-02-27 06:18 UTC (History)
1 user (show)

fix sourcefile attribute generation (556 bytes, patch)
2006-02-27 03:44 UTC, Dave Brosius
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Brosius 2006-02-23 23:57:11 UTC
doing javap on a jsp generated servlet from 5.5.9 starts with:

Compiled from "org.apache.jsp.WEB_002dINF.jsp.components.globalheader_jsp"
public final class org.apache.jsp.WEB_002dINF.jsp.components.globalheader_jsp 
extends org.apache.jasper.runtime.HttpJspBase implements 
  SourceFile: "org.apache.jsp.WEB_002dINF.jsp.components.globalheader_jsp"

That is, the SourceFile attribute of this class is 

But this is incorrect, according to the java class file specification, 
specifically section: 4.7.7 The SourceFile Attribute

"The string referenced by the sourcefile_index item will be interpreted as 
indicating the name of the source file from which this class file was 
compiled. It will not be interpreted as indicating the name of a directory 
containing the file or an absolute path name for the file; such platform-
specific additional information must be supplied by the runtime interpreter or 
development tool at the time the file name is actually used."

That means that for the above class, the SourceFile attribute should just be


Note, no package or path info, as well as the .java extension.

This wreaks havoc on tools such as BCEL, FindBugs, etc.
Comment 1 Dave Brosius 2006-02-24 00:05:22 UTC
By the way, this was not the case in the 5.0 series of tomcats.
Comment 2 Scott Johnson 2006-02-24 17:28:23 UTC
This is an Eclipse JDT compiler problem.  I searched Eclipse Bugzilla and didn't
see any bug resembling this so you could open a bug there.
Comment 3 Dave Brosius 2006-02-24 18:11:24 UTC
I guess i'm not following you. I delete my web-app's work directory. i start 
tomcat up with start.bat, i browse a few pages. I run javap on the generated 
servlet. I see these errors. How does eclipse have anything to do with it?
Comment 4 Scott Johnson 2006-02-24 19:28:06 UTC
Tomcat 5.5 uses the Eclipse JDT compiler, not javac, to compile JSP 'servlets'.
 Tomcat 5.0x uses javac. 
Comment 5 Olivier Thomann 2006-02-24 22:59:18 UTC
Please check https://bugs.eclipse.org/bugs/show_bug.cgi?id=129383#c5.
This comment suggests a fix for the org.apache.jasper.compiler.JDTCompiler class.
Once I fixed it following comment 5, I got the expected result.
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=129383#c9.

Let me know if there is anything I can do to help.
Comment 6 Dave Brosius 2006-02-24 23:01:09 UTC
Thank you Olivier!
Comment 7 Dave Brosius 2006-02-27 03:44:45 UTC
Created attachment 17801 [details]
fix sourcefile attribute generation

Olivier Thomann found this code that was incorrectly generating the source file
attribute in the class file. This patch fixes this.
Comment 8 Remy Maucherat 2006-02-27 15:18:23 UTC
Thanks for fixing this issue.