SocketPermission's implies() interesting behavior

Charles Lee littlee at
Thu Feb 17 09:19:56 UTC 2011

Hi guys,

I am reading the SocketPermission source code recently and find some 
thing strange. Below is a simple test case to describe the strange thing:

SocketPermission star_All = new SocketPermission("*", 
SocketPermission www_All = new SocketPermission("", 

star_All = new SocketPermission("", "listen,accept,connect");
www_All = new SocketPermission("", "listen,accept,connect");

Return is false and true.

The reason is:
SocketPermission treat wildcard special. If the initial string has a 
wildcard, the cname comes from the substring. For example, the cname of 
"*" is "". (Why the first dot remains?)
In my initial idea, "*" should imply "". Any idea about it?

More interestingly, I add "localhost.localdomain" and "mytest" pointing 
to the "" in the /etc/hosts (Ubuntu) and rewrite the test case to:

SocketPermission star_All = new 
SocketPermission("localhost.localdomain", "listen,accept,connect");
SocketPermission www_All = new SocketPermission("mytest", 

Return is true.

If on a multi-host machine, is it reasonable?

By the way, I am curious about the reason why SocketPermission does not 
use the initial string as its cname, for example:

SocketPermission star_All = new SocketPermission("*.blabla.bla", 
SocketPermission www_All = new SocketPermission("bla.blabla.bla", 

In the above test case, the two permission looks similiar. If using the 
initial string, I expect the return should be true. But it return false, 
because of the UnknowHostException. Any idea about this?

More information about the core-libs-dev mailing list