Another Usecase for ASM Classloading

February 18th, 2010

With regards to my last post (ASM for Classloading), another case in which I was tempted to use this technique was in a Google App Engine (GAE) project.  The Java version of GAE has a whitelist of what Java classes are allowed and transversely, which aren’t.  One of the classes that is not allowed is java.net.InetAddress.  This is understandable since the Inet addresses (IP and hostname) are of no consequence in a Cloud environment and quite meaningless.  However, many 3rd party libraries use InetAddress to generate UUID values.  Is this good practice?  No, but it happens.  Any 3rd party library that even references this class (it doesn’t need to actually use it, just have it as an import) will crash your application with a GAE whitelist exception.  Using the technique described here all referenced to InetAddress could be replaced with a fake InetAddress class that provided localhost (127.0.0.1) values for the methods of InetAddress.  Problem solved and no code would need to be hunted down, re-written and maintained.

Leave a Reply