The networkinggroup is a setof developers interested in the design, implementation, andmaintenance of the Java networking libraries.
The source code for the networking part of the core libraries isspread 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 guidanceis needed before you take upon the task of tinkering with thatbeast.
The networking source code resides mostly in thesedirectories:
src/share/classes/java/net
:
This is where the public API resides. You should get familiar withthe 67 classes and interfaces. If you're not there yet, a goodstart would be in thejavadoc of the java.net package.
src/share/classes/sun/net
:
This is where many of the protocol handlers are implemented, aswell as some other service providers like the default proxyselector, the DNS name resolver and some other utility classes. Inparticular the protocol handlers used by java.net.URLConnection arelocated in thewww/protocol
subdirectory.
src/solaris/native/java/net
:
This is one is a bit of a misnomer but this is for historicalreasons. This where you'll find most of the native code responsiblefor linking with the native networking stack (sockets, ioctl,etc...). It actually covers both Solaris and Linux, thanks to quitea few #ifdefs. This is where you'd have to do most of the work toadd support for another flavor of the Unix system.
src/windows/native/java/net
:
This is where the windows native code resides. During its 12+ yearsof existence it had to support Windows 95, 98, 98SE, ME, NT4, 2000,XP, 2003 and, more recently, Vista. This explains the complexity ofthe code in there, since the networking library of these variousversions of Windows changed very significantly from one version toanother. If you see a very strange piece of code in there that youcan't quite understand and seems pointless, don't be fooled, it'sthere for a reason.
src/shared/native/java/net
:
Here, you'll find a few utility functions used by all platformspecific native code implementation.
First, be aware that the networking components haveinterdependencies with quite a few other parts of the JDK. Evenmore so, it's one the components at the foundations of the JDK, soalways make sure you can rebuild everything from scratch afteryou've made changes.
Now, there are 2 areas where makefiles, and related files, arelocated:
make/java/net
make/sun/net
If you go to any of these 2 subdirectories you can issue amake
command and quickly compile your changes ineither package.
As a rule, unit tests, for new functionality, and regressiontests for fixes are mandatory. Which means you should provide aunit test for pretty much any change you make. The test directoriesfollow the same structure as the others:
test/java/net
:
Contains the unit and regression tests for the java.netpackage.
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 shouldalways run all the existing tests in these directories beforesubmitting them. Moreover, because of the dependencies, it ishighly recommend to also run the regression tests for the securitycomponents since the networking code is highly sensitive tosecurity. These are located intest/java/security
andtest/sun/security
. Needless to say, if any of thesetests fails, then you should investigate and fix the issue, or backout your changes.
Remember, there is no such thing as too much testing.