Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

JLS.17.5.4 Write Protected Fields

Thread view: 
ANONYMOUS.COWARD0xC0DE@gmail.com - 11 Aug 2007 04:09 GMT
/* from java/lang/System.java */
public final static InputStream in = nullInputStream();
[...]
java.lang.System.nullInputStream(void) simply returns null.

>From this I can not tell how the compiler would know to denote this as
a write protected field.
Do compilers simply hard code System.out,in,err as write protected
fields?
Mike Schilling - 11 Aug 2007 07:10 GMT
> /* from java/lang/System.java */
> public final static InputStream in = nullInputStream();
[quoted text clipped - 6 lines]
> Do compilers simply hard code System.out,in,err as write protected
> fields?

Yes, they are unique.  I recall that one of the papers describing the new
synchronization model for Java had to treat access to them specially, since
they're the only read-only but non-final fields in all of Java.  Obviously,
they should be accessed via getters, but there's no way to make that change
without breaking compatibility. [1]

1. OK, it's possible, but it's a lot of trouble.
Thomas Hawtin - 11 Aug 2007 14:03 GMT
> /* from java/lang/System.java */
> public final static InputStream in = nullInputStream();
[quoted text clipped - 5 lines]
> Do compilers simply hard code System.out,in,err as write protected
> fields?

It's the JVM which treats them specially.

Back in JDK 1.0 these fields were non-final. That is a security flaw.

1.1 made these fields final. It also added setIn/setErr/setOut. The
obvious implementation would be to have proxy streams on in/err/out.
However, what they actually do is change the final variables (through
native code).

1.5 gives the JVM some extra optimisation freedom for final variables
(presumably JVM were actually using some of this before it was legal).
To make in/err/out work correctly, the specification has to make special
cases for these three variables only.

Tom Hawtin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.