<< Quote Of The Day | Home | Fwd: Serious e1000e Driver Issue in SLE 11 Beta 1 and openSUSE 11.1 Beta 1 >>

Friday Java Moral Dilemma: import com.sun.net.httpserver.HttpServer;

Todays question stems from an answer to last week's quiz. In this answer, Solomon Duskis used two imports from the com.sun... package hierarchy:

import com.sun.net.httpserver.HttpServer;
import com.sun.jersey.api.container.httpserver.HttpServerFactory;

Q: (Pretend that these imports showed up in code in your project, and you are in a code review session prior to a release of the project) Should these imports be allowed to be used in your project? On what ground?

Tags :


Re: Friday Java Moral Dilemma: import com.sun.net.httpserver.HttpServer;

I think if it couldnt be done any other way it should be allowed, but first i would look for other ways of doing the thing that is needed. Here i think we are using it to start a web server, so i think it should be dropped and intergrate something like tomcat to the project. I think its a basic answer that most people will give, so i will save them a lot of time ;) where is the catch?

Re: Friday Java Moral Dilemma: import com.sun.net.httpserver.HttpServer;

I think a lot of us Java developers have been conditioned to think that we should only use published APIs in the java or javax hierarchy, and things under com.sun are implementation details that is not guaranteed to be there in the future.

But in this case, if one claim that com.sun.net.httpserver.HttpServer is an implementation detail, then the natural follow-up question to ask is "implementation detail of what?"

As for the urge to find an open-source implementation that offer similar functionality, that'll lead us right back to the Sun JDK, because the Sun JDK is now an open source project.

Re: Friday Java Moral Dilemma: import com.sun.net.httpserver.HttpServer;

I just ran into a case recently where an OSGi-based container threw a runtime error (not exception) because there were "com.sun.*" packages in the code. I assume this has to do with visibility restrictions in OSGi, though I am not familiar enough to say for sure (notice also that the default Eclipse 3.4 gives you compiler errors if you use internal packages). I imagine that when JSR-277 becomes part of the JDK, code using internal packages like this one will become problematic.

Re: Friday Java Moral Dilemma: import com.sun.net.httpserver.HttpServer;

I'd be skeptical. I'd want to know why they were importing that and if there's something else available that could do the same thing. For this, there are plenty of http servers you can easily embed that have APIs that are less likely to change.

Sometimes there's not. If you want to handle signals on the JVM for example, a com.sun import is pretty much the only way (or at least used to be, I haven't checked recently).

But such a thing should be kept from the rest of the code. Either by wrapping the com.sun packages or by having just a single class that can use it. It prevents making lots of painful edits when that api does change.

Add a comment Send a TrackBack