Java-8 – disadvantages of the javac – parameters flag

I want to try some framework functions that require parameter names at run time, so I need to compile my application with - parameters, which will store the name of the parameter in the JVM bytecode

Besides the size of jar / war, what are the disadvantages of this parameter usage?

Solution

JEP 118 provides parameter names in class file format, which is provided in Java 8 There is some discussion about why it is optional to include parameter names in the openjdk email thread here and here In short, the reason for making parameter names optional is concerns about class file size, compatibility surfaces, and exposure of sensitive information

The issue of compatibility deserves further discussion A thread linked above indicates that changing the parameter name is a binary compatible change This is true, but only in the strict context of the JVM binary compatibility concept That is, changing the parameter name of a method will never change whether the JVM can link the method However, this statement does not represent general compatibility

Historically, parameter names have been treated as local variable names (after all, they are local.) You can change them at will, and nothing outside the method will be affected However, if reflective access to parameter names is enabled, suddenly you cannot change the name without considering that other parts of the program may be using it To make matters worse, unless you have strict test cases for all use of parameter names, there is nothing to tell you, or you have a very good static analyzer that can find these situations (I don't know one)

These comments are associated with the problem of using Jackson (a JSON Processing Library), which has the ability to map method parameter names to JSON attribute names This may be very convenient, but it also means that if you change the parameter name, the JSON binding may break Worse, if the program generates JSON structures based on Java method parameter names, changing the method parameter names may silently change the data format or wired protocol Obviously, using this feature reliably in such an environment means that you have to do very good testing and add comments around the code to indicate which parameter names should not be changed

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>