The Networking Group
The networking group is a set of developers interested in the design, implementation, and maintenance of the Java networking libraries.
Introduction
The source code for the networking part of the core libraries is spread over a few hundreds files making for a total of, approximately, 70,000 lines of code. 50,000 of these are java code, while the rest is native (i.e. C) code. While this is not massive, due to the tricky nature of cross-platform support, some guidance is needed before you take upon the task of tinkering with that beast.
Projects
Source structure
The networking source code resides mostly in these directories:
-
src/share/classes/java/net
:
This is where the public API resides. You should get familiar with the 67 classes and interfaces. If you're not there yet, a good start would be in the javadoc of the java.net package. -
src/share/classes/sun/net
:
This is where many of the protocol handlers are implemented, as well as some other service providers like the default proxy selector, the DNS name resolver and some other utility classes. In particular the protocol handlers used by java.net.URLConnection are located in thewww/protocol
subdirectory. -
src/solaris/native/java/net
:
This is one is a bit of a misnomer but this is for historical reasons. This where you'll find most of the native code responsible for linking with the native networking stack (sockets, ioctl, etc...). It actually covers both Solaris and Linux, thanks to quite a few #ifdefs. This is where you'd have to do most of the work to add support for another flavor of the Unix system. -
src/windows/native/java/net
:
This is where the windows native code resides. During its 12+ years of existence it had to support Windows 95, 98, 98SE, ME, NT4, 2000, XP, 2003 and, more recently, Vista. This explains the complexity of the code in there, since the networking library of these various versions of Windows changed very significantly from one version to another. If you see a very strange piece of code in there that you can't quite understand and seems pointless, don't be fooled, it's there for a reason. -
src/shared/native/java/net
:
Here, you'll find a few utility functions used by all platform specific native code implementation.
Building the networking libraries
First, be aware that the networking components have interdependencies with quite a few other parts of the JDK. Even more so, it's one the components at the foundations of the JDK, so always make sure you can rebuild everything from scratch after you've made changes.
Now, there are 2 areas where makefiles, and related files, are located:
-
make/java/net
-
make/sun/net
If you go to any of these 2 subdirectories you can issue a
make
command and quickly compile your changes in
either package.
Testing your changes
As a rule, unit tests, for new functionality, and regression tests for fixes are mandatory. Which means you should provide a unit test for pretty much any change you make. The test directories follow the same structure as the others:
-
test/java/net
:
Contains the unit and regression tests for the java.net package. -
test/sun/net
:
Contains the unit and regression tests for the sun.net package.
Not only should you write tests for your changes but you should
always run all the existing tests in these directories before
submitting them. Moreover, because of the dependencies, it is
highly recommend to also run the regression tests for the security
components since the networking code is highly sensitive to
security. These are located in test/java/security
and
test/sun/security
. Needless to say, if any of these
tests fails, then you should investigate and fix the issue, or back
out your changes.
Remember, there is no such thing as too much testing.
Documentation
Community
- Mailing lists