I came across this method in the JD开发者_运维问答K
From com.sun.org.apache.xml.internal.serializer.Version;
public static int getDevelopmentVersionNum()
{
try {
if ((new String("")).length() == 0)
return 0;
else
return Integer.parseInt("");
} catch (NumberFormatException nfe) {
return 0;
}
}
Is this doing anything more than return 0
?
I feel like I am missing something. I can only assume this is generated code. ;)
It looks like this file is generated from the following Version.src
file by textual substitution. So, when @version.DEVELOPER@
variable is empty, the code in question is generated. length()
check is needed to return 0 in this case.
I think ""
is replaced with some string from a configuration file before release. In this case it is empty, but it may also contain a number. If you consider ""
to be a variable, this code makes some sense.
The javadoc on the method indicates that it's meant to designate a development drop that is work in progress. So I would say it makes as much sense as anything else that's meant for internal development use only. It could be that they "wash away" any actual version information from this method once they do a release. Either way, I would not place any significance on it. Unless you are a developer at oracle, working on this particular package.
Yes, there's probably a generator/preprocessor, which outputs a string in both if's.
If this string is a number, the method returns its value as a number. If it's empty (as in this case) or not a number, it returns 0.
Looks like the original xalan has a similiar implementation - at least I found the same lines for xalan 2.7.1 at grepcode
It really doesn't make any sense, to much effort for a method that always returns 0
;) But from looking at the javaDoc of Version
and this method I get the impression that all of this is (or was) work in progress - some sort of implementation stub where one can simply enter (hardcode) a version number. For now, the else block and the catch block are unreachable code.
Maybe Version.java
is/will be autogenerated and the processor may generate this method with a real value instead of ""
- in that case it would make sense to secure the method, as the value from the config file may not represent an integer.
精彩评论