<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: You CAN Change Final Fields</title>
	<atom:link href="http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/feed/" rel="self" type="application/rss+xml" />
	<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/</link>
	<description>Technology and Geek Stuff by Eric Burke</description>
	<lastBuildDate>Thu, 04 Nov 2010 22:37:00 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rémi Forax</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-357</link>
		<dc:creator>Rémi Forax</dc:creator>
		<pubDate>Tue, 16 Oct 2007 20:26:51 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-357</guid>
		<description>For the record, you can change final field value using reflection with
1.1, 1.2, 1.5 and 1.6 VM not with 1.3 and 1.4,
this feature was disable after 1.3 and re-enable in 1.5,
following the recommandation of JSR 133 expert group (memory model).

Rémi</description>
		<content:encoded><![CDATA[<p>For the record, you can change final field value using reflection with<br />
1.1, 1.2, 1.5 and 1.6 VM not with 1.3 and 1.4,<br />
this feature was disable after 1.3 and re-enable in 1.5,<br />
following the recommandation of JSR 133 expert group (memory model).</p>
<p>Rémi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Burke</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-351</link>
		<dc:creator>Eric Burke</dc:creator>
		<pubDate>Tue, 16 Oct 2007 11:54:10 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-351</guid>
		<description>@qinxian none of these are bugs or broken. I never said that or even implied it. But people are apparently confused by my usage of the word &quot;surprising&quot;. Sigh.

I am thinking along the lines of topics mentioned in the book &quot;Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases&quot;. An entire book of perfectly legal, valid, non-buggy code that is surprising. If it were not surprising, the book wouldn&#039;t have much of a reason to exist. For the record, other languages (say C++ or Ruby) have 10x the number of surprising, but legal, features.</description>
		<content:encoded><![CDATA[<p>@qinxian none of these are bugs or broken. I never said that or even implied it. But people are apparently confused by my usage of the word &#8220;surprising&#8221;. Sigh.</p>
<p>I am thinking along the lines of topics mentioned in the book &#8220;Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases&#8221;. An entire book of perfectly legal, valid, non-buggy code that is surprising. If it were not surprising, the book wouldn&#8217;t have much of a reason to exist. For the record, other languages (say C++ or Ruby) have 10x the number of surprising, but legal, features.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: qinxian</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-349</link>
		<dc:creator>qinxian</dc:creator>
		<pubDate>Tue, 16 Oct 2007 10:44:40 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-349</guid>
		<description>Should we take it as a BUG of reflection function, which broken language spec? isn&#039;t it?</description>
		<content:encoded><![CDATA[<p>Should we take it as a BUG of reflection function, which broken language spec? isn&#8217;t it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Artur Biesiadowski</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-347</link>
		<dc:creator>Artur Biesiadowski</dc:creator>
		<pubDate>Tue, 16 Oct 2007 09:24:43 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-347</guid>
		<description>Take a look at sun.misc.Unsafe class. If you have full privilages in jvm (like you need for setAccessible(true)), you can do a lot more funny things. With Unsafe class you can just modify any place in memory to any value - including change of class of the object, overwriting pointers to one object with pointers to noncompatible objects etc. Of course, crashing jvm is easiest of those options.

So, either speak about what is possibile in java in secured environment (like applets) - or don&#039;t be surprised by anything, because with enough trickery, you can do whatever you want by direct memory manipulation. setAccessible(true) and setting final field is just a different form of direct memory manipulation, skipping normal accessibility rules (private, final, whatever).</description>
		<content:encoded><![CDATA[<p>Take a look at sun.misc.Unsafe class. If you have full privilages in jvm (like you need for setAccessible(true)), you can do a lot more funny things. With Unsafe class you can just modify any place in memory to any value &#8211; including change of class of the object, overwriting pointers to one object with pointers to noncompatible objects etc. Of course, crashing jvm is easiest of those options.</p>
<p>So, either speak about what is possibile in java in secured environment (like applets) &#8211; or don&#8217;t be surprised by anything, because with enough trickery, you can do whatever you want by direct memory manipulation. setAccessible(true) and setting final field is just a different form of direct memory manipulation, skipping normal accessibility rules (private, final, whatever).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Burke</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-323</link>
		<dc:creator>Eric Burke</dc:creator>
		<pubDate>Mon, 15 Oct 2007 12:26:29 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-323</guid>
		<description>@cm when I wrote one line of code that set a value, and the very next line of code I &quot;retrieved&quot; the value and saw the old data, I WAS SURPRISED.</description>
		<content:encoded><![CDATA[<p>@cm when I wrote one line of code that set a value, and the very next line of code I &#8220;retrieved&#8221; the value and saw the old data, I WAS SURPRISED.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cm</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-322</link>
		<dc:creator>cm</dc:creator>
		<pubDate>Mon, 15 Oct 2007 11:40:34 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-322</guid>
		<description>Hi

This optimization is called inlining. The results are not surprising.
Try to decompile the class to see what actually happens.

Altough I agree you shouldn&#039;t change final field via reflection.</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>This optimization is called inlining. The results are not surprising.<br />
Try to decompile the class to see what actually happens.</p>
<p>Altough I agree you shouldn&#8217;t change final field via reflection.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Burke</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-315</link>
		<dc:creator>Eric Burke</dc:creator>
		<pubDate>Sun, 14 Oct 2007 18:46:58 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-315</guid>
		<description>@Carsten I show setSecurityManager(...) and discuss suppressAccessChecks in my previous post.</description>
		<content:encoded><![CDATA[<p>@Carsten I show setSecurityManager(&#8230;) and discuss suppressAccessChecks in my previous post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carsten</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-311</link>
		<dc:creator>Carsten</dc:creator>
		<pubDate>Sun, 14 Oct 2007 09:03:31 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-311</guid>
		<description>Note that setAccesible can throw a SecurityException - if there is is a SecurityManager you need to have the suppressAccessChecks permission. Thus no violation of access control, although very few apps run with a SecurityManager (virtually all Tomcat installations). Simply add to you main method: System.setSecurityManager(new SecurityManager()); and the hack will cease to work. Highly recommended if you write code that is supposed to run on an Appserver.

The optimization you have seen is technically not an optimization, final values of non-objects and String are allowed to be inlined by the compiler (you&#039;ll find this somewhere in the JLS). If you use a Number object the first version of your code with set(caveman, Integer.valueOf(100)) will return 100.</description>
		<content:encoded><![CDATA[<p>Note that setAccesible can throw a SecurityException &#8211; if there is is a SecurityManager you need to have the suppressAccessChecks permission. Thus no violation of access control, although very few apps run with a SecurityManager (virtually all Tomcat installations). Simply add to you main method: System.setSecurityManager(new SecurityManager()); and the hack will cease to work. Highly recommended if you write code that is supposed to run on an Appserver.</p>
<p>The optimization you have seen is technically not an optimization, final values of non-objects and String are allowed to be inlined by the compiler (you&#8217;ll find this somewhere in the JLS). If you use a Number object the first version of your code with set(caveman, Integer.valueOf(100)) will return 100.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: It&#8217;s Just a Bunch of Stuff That Happens &#187; Blog Archive &#187; On the Violation of Java Access Control</title>
		<link>http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/comment-page-1/#comment-305</link>
		<dc:creator>It&#8217;s Just a Bunch of Stuff That Happens &#187; Blog Archive &#187; On the Violation of Java Access Control</dc:creator>
		<pubDate>Sun, 14 Oct 2007 01:22:07 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/#comment-305</guid>
		<description>[...] BPM: Not Even Comic-Worthy You CAN Change Final Fields &#187;      Oct [...]</description>
		<content:encoded><![CDATA[<p>[...] BPM: Not Even Comic-Worthy You CAN Change Final Fields &raquo;      Oct [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.391 seconds -->

