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 / April 2007

Tip: Looking for answers? Try searching our database.

Extending the standard packages: is it legal?

Thread view: 
z-man - 21 Apr 2007 08:47 GMT
Hello all,

skimmin' through many Java open source code bases, I noticed that it
seems to be an established policy to put ancillary (utility) classes in
packages like %projectRootPackage%.util, despite often being just
extensions of standard packages (e.g.: a general-purpose custom
collection class).

Now I face a similar situation: I've implemented a general-purpose
exception class (mypackageroot.lang.NotImplementedException) that just
covers a generic functionality that I would have expected to be inside
the standard platform: I feel it would be MUCH more elegant to place it
under its "natural" location (java.lang package), because relating it
strictly to my package root seems to insert an alien within my project
space.

So, is there any argument against my perception?
At the bottom line, is it contractually legal to extend the standard
J2SE packages with custom classes? May I incur into license violations
with Sun?

Thank you
Thomas Kellerer - 21 Apr 2007 09:42 GMT
z-man wrote on 21.04.2007 09:47:
> Now I face a similar situation: I've implemented a general-purpose
> exception class (mypackageroot.lang.NotImplementedException) that just
[quoted text clipped - 8 lines]
> J2SE packages with custom classes? May I incur into license violations
> with Sun?

Although I don't think there is a license issue, I would still try to avoid this
for reasons of documentation.

If someone else joins your team or needs to extend your work, this naming
convention could be very irritating. If I see a class that is located in
java.lang I expect to find the documentation in the JDK API but in your project
I wouldn't

Thomas
Sherm Pendley - 21 Apr 2007 09:59 GMT
> At the bottom line, is it contractually legal to extend the standard
> J2SE packages with custom classes? May I incur into license violations
> with Sun?

I haven't read their newer licenses, but that was the core of Sun's lawsuit
against Microsoft. MS had added classes (or methods, I forget which) in the
java.* package which were in fact unique to MS's own JVM. Clearly the intent
was to deceive developers into unknowningly writing Windows-only Java apps,
undermining its cross-platform promise.

Having said that, there's a *huge* difference between adding a java.* class
to your app, and adding one to your own JVM. I think Sun's license would
really only be relevant if you were doing to latter, and if you wanted to
refer to it by the trademarked name "Java".

For the record, I am not a lawyer.

sherm--

Signature

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net

Arne Vajhøj - 21 Apr 2007 18:49 GMT
>> At the bottom line, is it contractually legal to extend the standard
>> J2SE packages with custom classes? May I incur into license violations
[quoted text clipped - 5 lines]
> was to deceive developers into unknowningly writing Windows-only Java apps,
> undermining its cross-platform promise.

As I recall it then it was more the missing parts than the extra
parts that got them in problems.

Arne
Bent C Dalager - 22 Apr 2007 09:14 GMT
>> At the bottom line, is it contractually legal to extend the standard
>> J2SE packages with custom classes? May I incur into license violations
[quoted text clipped - 5 lines]
>was to deceive developers into unknowningly writing Windows-only Java apps,
>undermining its cross-platform promise.

As I remember, this wasn't a license issue but a contract issue:
Microsoft had sigend a contract with Sun where they said they wouldn't
do this and then they did anyway.

>Having said that, there's a *huge* difference between adding a java.* class
>to your app, and adding one to your own JVM. I think Sun's license would
>really only be relevant if you were doing to latter, and if you wanted to
>refer to it by the trademarked name "Java".

I would think the license says something explicit about not being
allowed to redistribute an altered VM.

Cheers
    Bent D
Signature

Bent Dalager - bcd@pvv.org - http://www.pvv.org/~bcd
                                   powered by emacs

Adam Maass - 21 Apr 2007 10:21 GMT
> Hello all,
>
[quoted text clipped - 16 lines]
> J2SE packages with custom classes? May I incur into license violations
> with Sun?

Section 6.8.1 of the JLS (3rd edition) states that package names starting
with 'java' are reserved by Sun.

(See
http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.8.1 )

It used to be the case that there was a developers note on the java* and
sun* packages that explained the rationale for developers not writing new
code in those packages. I can't seem to find it now, but it was there ages
ago.

I believe the license on Java VMs (used to, anyway) forbid adding classes to
those packages.

I've heard (but not verified) that the Sun VMs have special-case handling
for classes that live the java* packages, particularly java.lang. Because of
that special handling, you might get unexpected behavior.

Might I suggest using 'java.lang.UnsupportedOperationException' instead of
your custom 'NotImplementedException'? (Generally, a developer ought to be
throwing exceptions that are already defined in the libraries instead of
writing their own -- when the exception makes sense!)

-- Adam Maass
Lew - 21 Apr 2007 14:12 GMT
"z-man" <nospam@nowhere.zz> wrote:
>> I feel it would be MUCH more elegant to place it
>> under its "natural" location (java.lang package), because relating it
[quoted text clipped - 4 lines]
>> J2SE packages with custom classes? May I incur into license violations
>> with Sun?

> Section 6.8.1 of the JLS (3rd edition) states that package names starting with 'java' are reserved by Sun.
>
> (See http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.8.1 )
...
> Might I suggest using 'java.lang.UnsupportedOperationException' instead
> of your custom 'NotImplementedException'? (Generally, a developer ought
> to be throwing exceptions that are already defined in the libraries
> instead of writing their own -- when the exception makes sense!)

It also both stupid and unnecessary to add to java[x].*.  You can extend, say,
Exception just fine in your own domain, no need to pretend to be in Sun's.

The stupid part is that to add to java[x].* is to declare that your code is
part of the Java language itself, which is anything but "natural".  It would
render your code unusable outside your private world.

Are you really thinking that your class is part of the whole language?  It
seems much more "natural" to think of your /custom/ class as part of /your/
package than Java's, eh?  At least, that's how it would seem to a Java programmer.

Signature

Lew

Richard Senior - 21 Apr 2007 19:21 GMT
> The stupid part is that to add to java[x].* is to declare that your code
> is part of the Java language itself, which is anything but "natural".  
> It would render your code unusable outside your private world.

Exactly. What happens if Sun decide to create a NotSupportedException?
They are perfectly entitled to do that and your program breaks. The
whole point of the namespace convention based on reverse domain name is
to avoid such conflicts.

Richard
Arne Vajhøj - 21 Apr 2007 18:57 GMT
> skimmin' through many Java open source code bases, I noticed that it
> seems to be an established policy to put ancillary (utility) classes in
[quoted text clipped - 14 lines]
> J2SE packages with custom classes? May I incur into license violations
> with Sun?

In general I would consider it bad practice to hijack others packages,
because it gives the impression that somebody else is responsible.

java. and javax. for the public API's - all other uses reverse
internet domains - that is the prescribed naming convention.

Within your reverse internet domain you are free to choose whetever
package structure you prefer.

Arne
pkriens - 22 Apr 2007 11:59 GMT
Extending other people's packages is almost always wrong. In the case
of java packages, it is double wrong.

It is wrong to extend other people's packages because the default
package protection mechanism can fail (two classes in the same package
can not see each others package private variables and methods). The
reason is that these classes are loaded by different classloaders.
Because you have different class loaders loading the same package, you
also easily get shadowing of classes with the same name.

Extending java.lang is doubly bad, but also likely to be impossible.
Common classloading rules first look in the parent classloader. The
loader that loads java.lang is at the top and therefore gets the first
try. It is possible to seal packages, which means that only one
classloader may provide a package.

The OSGi specifications, a dynamic module system for Java
(www.osgi.org), the rule is therefore to always delegate java classes
to the parent.

Classloading is a complicated and messy business. Please do not muck
around with it if you want your code to run. If you do, it is likely
the legal aspects are your small problem over time. One of the great
inventions of Java is the global namespace that is used. Mucking with
other people's packages violates a lot of assumptions and will bite
you.

Kind regards,

   Peter Kriens

> Hello all,
>
[quoted text clipped - 3 lines]
> extensions of standard packages (e.g.: a general-purpose custom
> collection class).

> Now I face a similar situation: I've implemented a general-purpose
> exception class (mypackageroot.lang.NotImplementedException) that just
[quoted text clipped - 10 lines]
>
> Thank you
Esmond Pitt - 23 Apr 2007 03:23 GMT
In addition to all that has been said here, summarized by 'don't', if
your code ever runs under a security manager it will throw an exception
because defining classes in the java.* or sun.* packages requires a
permission.
Tom Hawtin - 23 Apr 2007 03:36 GMT
> In addition to all that has been said here, summarized by 'don't', if
> your code ever runs under a security manager it will throw an exception
> because defining classes in the java.* or sun.* packages requires a
> permission.

You can't even define a class in java.* if you have all the permission
in the world (well, okay you may be able to use, say, reflection to hack
around it). The check for java. is in ClassLoader, and it doesn't check
for a security manager. You would have to run the JVM with -Xbootclasspath.

sun.* (and couple com.sun subpackage in Java WebStart/PlugIn) are
restricted with the package.access security property.

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.