126
127 private static boolean isThisParameter(ValueNode node) {
128 return node instanceof ParameterNode && ((ParameterNode) node).index() == 0;
129 }
130
131 /**
132 * Checks whether the type of {@code x} is assignable to the restricted type and that {@code y}
133 * is not a null constant.
134 */
135 private boolean isIllegalUsage(ResolvedJavaMethod method, ValueNode x, ValueNode y, MetaAccessProvider metaAccess) {
136 if (isAssignableToRestrictedType(x, metaAccess) && !isNullConstant(y)) {
137 if (isEqualsMethod(method) && isThisParameter(x) || isThisParameter(y)) {
138 return false;
139 }
140 return true;
141 }
142 return false;
143 }
144
145 @Override
146 protected boolean verify(StructuredGraph graph, PhaseContext context) {
147 for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) {
148 // bail out if we compare an object of type klass with == or != (except null checks)
149 ResolvedJavaMethod method = graph.method();
150 ResolvedJavaType restrictedType = context.getMetaAccess().lookupJavaType(restrictedClass);
151
152 if (method.getDeclaringClass().equals(restrictedType)) {
153 // Allow violation in methods of the restricted type itself.
154 } else if (isIllegalUsage(method, cn.getX(), cn.getY(), context.getMetaAccess()) || isIllegalUsage(method, cn.getY(), cn.getX(), context.getMetaAccess())) {
155 throw new VerificationError("Verification of " + restrictedClass.getName() + " usage failed: Comparing " + cn.getX() + " and " + cn.getY() + " in " + method +
156 " must use .equals() for object equality, not '==' or '!='");
157 }
158 }
159 return true;
160 }
161 }
|
126
127 private static boolean isThisParameter(ValueNode node) {
128 return node instanceof ParameterNode && ((ParameterNode) node).index() == 0;
129 }
130
131 /**
132 * Checks whether the type of {@code x} is assignable to the restricted type and that {@code y}
133 * is not a null constant.
134 */
135 private boolean isIllegalUsage(ResolvedJavaMethod method, ValueNode x, ValueNode y, MetaAccessProvider metaAccess) {
136 if (isAssignableToRestrictedType(x, metaAccess) && !isNullConstant(y)) {
137 if (isEqualsMethod(method) && isThisParameter(x) || isThisParameter(y)) {
138 return false;
139 }
140 return true;
141 }
142 return false;
143 }
144
145 @Override
146 protected void verify(StructuredGraph graph, PhaseContext context) {
147 for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) {
148 // bail out if we compare an object of type klass with == or != (except null checks)
149 ResolvedJavaMethod method = graph.method();
150 ResolvedJavaType restrictedType = context.getMetaAccess().lookupJavaType(restrictedClass);
151
152 if (method.getDeclaringClass().equals(restrictedType)) {
153 // Allow violation in methods of the restricted type itself.
154 } else if (isIllegalUsage(method, cn.getX(), cn.getY(), context.getMetaAccess()) || isIllegalUsage(method, cn.getY(), cn.getX(), context.getMetaAccess())) {
155 throw new VerificationError("Verification of " + restrictedClass.getName() + " usage failed: Comparing " + cn.getX() + " and " + cn.getY() + " in " + method +
156 " must use .equals() for object equality, not '==' or '!='");
157 }
158 }
159 }
160 }
|