Skip to content

Commit

Permalink
Print exceptions as warning when incomplete class hierarchies are all…
Browse files Browse the repository at this point in the history
…owed
  • Loading branch information
blendhamiti committed Aug 16, 2024
1 parent a80d389 commit b1772a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package proguard.evaluation.exception;

import proguard.evaluation.value.TypedReferenceValue;

/**
* Represents an exception during partial evaluation when an incomplete class hierarchy was
* encountered.
Expand All @@ -26,5 +28,7 @@ public class IncompleteClassHierarchyException
extends proguard.evaluation.IncompleteClassHierarchyException {
public IncompleteClassHierarchyException(String message) {
super(message);

TypedReferenceValue.INCOMPLETE_CLASS_HIERARCHY = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import proguard.classfile.AccessConstants;
import proguard.classfile.ClassConstants;
import proguard.classfile.Clazz;
Expand All @@ -48,10 +50,23 @@
*/
public class TypedReferenceValue extends ReferenceValue {

/** Indicates whether there were occurrences of {@link IncompleteClassHierarchyException}. */
public static boolean INCOMPLETE_CLASS_HIERARCHY = false;

/** If true, do not throw an {@link IncompleteClassHierarchyException} when one would occur. */
public static boolean ALLOW_INCOMPLETE_CLASS_HIERARCHY =
System.getProperty("allow.incomplete.class.hierarchy") != null;

/**
* If true, print warnings for occurrences of {@link IncompleteClassHierarchyException} when
* ALLOW_INCOMPLETE_CLASS_HIERARCHY is enabled.
*/
public static boolean WARN_INCOMPLETE_CLASS_HIERARCHY = false;

private static final boolean DEBUG = false;

private static final Logger logger = LogManager.getLogger(TypedReferenceValue.class);

protected final String type;
protected final Clazz referencedClass;
protected final boolean mayBeExtension;
Expand Down Expand Up @@ -300,6 +315,9 @@ public ReferenceValue generalize(TypedReferenceValue other) {
} catch (IncompleteClassHierarchyException e) {
// The class hierarchy seems to be incomplete.
if (ALLOW_INCOMPLETE_CLASS_HIERARCHY) {
if (WARN_INCOMPLETE_CLASS_HIERARCHY) {
logger.warn("Warning: Incomplete class hierarchy: {}", e.getMessage());
}
// We'll return an unknown reference value.
return BasicValueFactory.REFERENCE_VALUE;
}
Expand Down

0 comments on commit b1772a7

Please sign in to comment.