<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CertPal &#187; code too large</title>
	<atom:link href="http://www.certpal.com/blogs/tag/code-too-large/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.certpal.com/blogs</link>
	<description>Technology and certifications</description>
	<lastBuildDate>Tue, 24 Aug 2010 17:47:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Code too large for try statement ?</title>
		<link>http://www.certpal.com/blogs/2009/08/code-too-large-for-try-statement/</link>
		<comments>http://www.certpal.com/blogs/2009/08/code-too-large-for-try-statement/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 04:44:59 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[code too large]]></category>
		<category><![CDATA[try]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=94</guid>
		<description><![CDATA[An article on how the "Code too large for try statement" compilation error can occur in java when you least expect it.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F08%2Fcode-too-large-for-try-statement%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F08%2Fcode-too-large-for-try-statement%2F" height="61" width="51" /></a></div><p>If you didn&#8217;t already know it, the java language specification has limits on the size of a method. That limit is 65535 (number of bytes that the code occupies).</p>
<p>This so called limitation has never really bothered me. After practicing object oriented programming, modularization and good design principles you can only ask yourself &#8216;Who is crazy enough to write a method whose size is greater than 65535 !?&#8217;. But you know what ? It can happen. There are so many code gen tools out there and common libraries that will write code for you. Rules engines, JSP compilers, scripting/template engines will write dynamic code for you. If they do not write it withing the 65535 bytes limit, your code will not compile or will give a cryptic error and die.</p>
<p>Code suffering from this phenomenon will see this message &#8211; &#8220;<strong>Code too large to compile</strong>&#8221; or &#8220;<strong>Code too large for try statement</strong>&#8220;. So umm.. where did the try statement come from ?</p>
<p>Jave Server Page (JSP) templates sometimes follow a syntax that resembles this</p>
<p># Include Header<br />
try<br />
{<br />
# Content<br />
}<br />
catch(Exception e)<br />
{<br />
//Handle it<br />
}<br />
# footer</p>
<p>If you end up writing complex logic in your JSP and include (static includes) other files to partake in the final output, you might end up breaking your page. The error is not necessarily well defined. The same JSP page which might compile with version 8 of weblogic will fail  in version 10 or might compile in tomcat and fail in JBOSS. This is because each container writes code within the JSP in its own way.</p>
<p>The try catch may not even be introduced by you. Your container may introduce the try catch (for whatever internal reasons) for code written in the JSP. This problem is famous for creeping up when you move from one container to another or shift between container versions. The error occurs either when you request for a JSP page the first time (and the container tries to compile it) or when you try to pre compile the JSP for performance reasons.</p>
<p><strong>Solution:</strong></p>
<p>Help your container modularize the code. Try splitting the JSP into several chunks and make dynamic includes instead of static ones. Dynamic includes (jsp:include against %@include) will compile the JSP and then stream the output instead of trying to include all the code into one big method or try catch block.</p>
<p>You can read up on the limitation here</p>
<p><a href="http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html" target="_self">http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html</a></p>
<p>Look for this text</p>
<blockquote><p>The value of the code_length item must be less than 65536</p></blockquote>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2009/08/code-too-large…-try-statement/';</script><br />
<script type="text/javascript">var dzone_title = 'Code too large for try statement ?';</script><br />
<script type="text/javascript">var dzone_blurb = 'An article on how the "Code too large for try statement" compilation error can occur in java when you least expect it.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script><br />
<meta name="blogcatalog" content="9BC9417450" /></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F08%2Fcode-too-large-for-try-statement%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F08%2Fcode-too-large-for-try-statement%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2009/08/code-too-large-for-try-statement/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
