-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linkage Checker to verify method references to JRE classes #1607
Conversation
<LinkageError> | ||
<Target> | ||
<Class name="java.lang.invoke.MethodHandle" /> | ||
</Target> | ||
<Source> | ||
<Package name="com.oracle.svm" /> | ||
</Source> | ||
<Reason> | ||
GraalVM-related libraries depend on Java Compiler Interface (JVMCI) that | ||
only exists in special JDK. These missing classes are false positives, because | ||
the code is only invoked when running in a GraalVM. | ||
https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/929 | ||
</Reason> | ||
</LinkageError> | ||
<LinkageError> | ||
<Target> | ||
<Class name="java.lang.invoke.MethodHandle" /> | ||
</Target> | ||
<Source> | ||
<Package name="com.oracle.graal" /> | ||
</Source> | ||
<Reason> | ||
GraalVM-related libraries depend on Java Compiler Interface (JVMCI) that | ||
only exists in special JDK. These missing classes are false positives, because | ||
the code is only invoked when running in a GraalVM. | ||
https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/929 | ||
</Reason> | ||
</LinkageError> | ||
<LinkageError> | ||
<Target> | ||
<Class name="java.lang.invoke.MethodHandle" /> | ||
</Target> | ||
<Source> | ||
<Package name="org.graalvm" /> | ||
</Source> | ||
<Reason> | ||
GraalVM-related libraries depend on Java Compiler Interface (JVMCI) that | ||
only exists in special JDK. These missing classes are false positives, because | ||
the code is only invoked when running in a GraalVM. | ||
https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/929 | ||
</Reason> | ||
</LinkageError> | ||
<LinkageError> | ||
<Target> | ||
<Class name="java.lang.invoke.MethodHandle" /> | ||
</Target> | ||
<Source> | ||
<Package name="com.oracle.truffle" /> | ||
</Source> | ||
<Reason> | ||
GraalVM-related libraries depend on Java Compiler Interface (JVMCI) that | ||
only exists in special JDK. These missing classes are false positives, because | ||
the code is only invoked when running in a GraalVM. | ||
https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/929 | ||
</Reason> | ||
</LinkageError> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because now we check JDK classes, GraalVM-related exclusion is needed.
@Test | ||
public void testFindLinkageProblems_referenceToNonexistentMethodForJava8() throws IOException { | ||
// Protobuf-java 3.12.4 contained wrong byte code to reference non-existent method in JRE 1.8 | ||
// https://github.com/protocolbuffers/protobuf/issues/7827 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is Kristen's finding yesterday.
@@ -239,8 +239,14 @@ private boolean problemFilter(LinkageProblem linkageProblem) { | |||
String targetClassName = symbol.getClassBinaryName(); | |||
String methodName = symbol.getName(); | |||
|
|||
// Skip references to Java runtime class. For example, java.lang.String. | |||
if (classDumper.isSystemClass(targetClassName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was hiding the protobuf's linkage error against Java 8 runtime protocolbuffers/protobuf#7827
return Optional.empty(); | ||
} | ||
// Skip references from Java runtime class. For example, java.lang.String. | ||
// It is possible for wrongly configured Java compiler to generate bad byte code that references |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure lines 246-248 explain this code. It explains what we're not doing, not what we are. I suggest deleting them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this if-statement and moved the explanation to array class skipping.
|
||
@Test | ||
public void testFindLinkageProblems_referenceToNonexistentMethodForJava8() throws IOException { | ||
// Protobuf-java 3.12.4 contained wrong byte code to reference non-existent method in JRE 1.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protobuf-java 3.12.4 references a Java 11 method that does not exist in Java 8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really interesting one. Some take-aways:
- The compiler doesn't catch all linkage errors, even to classes in the JDK.
- We should report errors that the project (here Kristen) can't fix so they can understand them and report the errors to the team that can fix them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elharo PTAL.
|
||
@Test | ||
public void testFindLinkageProblems_referenceToNonexistentMethodForJava8() throws IOException { | ||
// Protobuf-java 3.12.4 contained wrong byte code to reference non-existent method in JRE 1.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
return Optional.empty(); | ||
} | ||
// Skip references from Java runtime class. For example, java.lang.String. | ||
// It is possible for wrongly configured Java compiler to generate bad byte code that references |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this if-statement and moved the explanation to array class skipping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs merge with master
@@ -126,8 +126,7 @@ JavaClass loadJavaClass(String className) throws ClassNotFoundException { | |||
/** Returns true if {@code className} is available in the system class loader. */ | |||
boolean isSystemClass(String className) { | |||
try { | |||
if (className.startsWith("[")) { | |||
// Array class | |||
if (isArrayClass(className)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will we catch a reference to an array of a missing class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but not from array class reference. When there's a reference to array of a class, there should be a reference to the class in the same class file.
// Skip references to Java runtime class. For example, java.lang.String. | ||
if (classDumper.isSystemClass(targetClassName)) { | ||
if (ClassDumper.isArrayClass(targetClassName)) { | ||
// Skip references to array class. However, we want to check other JDK-provided classes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this comment. It describes what the code is not doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elharo PTAL.
@@ -126,8 +126,7 @@ JavaClass loadJavaClass(String className) throws ClassNotFoundException { | |||
/** Returns true if {@code className} is available in the system class loader. */ | |||
boolean isSystemClass(String className) { | |||
try { | |||
if (className.startsWith("[")) { | |||
// Array class | |||
if (isArrayClass(className)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but not from array class reference. When there's a reference to array of a class, there should be a reference to the class in the same class file.
// Skip references to Java runtime class. For example, java.lang.String. | ||
if (classDumper.isSystemClass(targetClassName)) { | ||
if (ClassDumper.isArrayClass(targetClassName)) { | ||
// Skip references to array class. However, we want to check other JDK-provided classes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge to master please
Fixes #1605 .