Skip to content

Commit

Permalink
Issue #12: More checks that the lambdas groupId hack is only used for…
Browse files Browse the repository at this point in the history
… INDY calls, not when used with other constant references (LDC)
  • Loading branch information
uschindler committed Dec 26, 2014
1 parent b634d3f commit 4fca034
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/de/thetaphi/forbiddenapis/ClassScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private String checkFieldAccess(String owner, String field) {
return null;
}

private String checkHandle(Handle handle) {
private String checkHandle(Handle handle, boolean indy) {
switch (handle.getTag()) {
case Opcodes.H_GETFIELD:
case Opcodes.H_PUTFIELD:
Expand All @@ -369,7 +369,7 @@ private String checkHandle(Handle handle) {
case Opcodes.H_NEWINVOKESPECIAL:
case Opcodes.H_INVOKEINTERFACE:
final Method m = new Method(handle.getName(), handle.getDesc());
if (handle.getOwner().equals(internalName) && handle.getName().startsWith("lambda$")) {
if (indy && handle.getOwner().equals(internalName) && handle.getName().startsWith("lambda$")) {
// as described in <http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html>,
// we will record this metafactory call as "lamda" invokedynamic,
// so we can assign the called lambda with the same groupId like *this* method:
Expand All @@ -380,11 +380,11 @@ private String checkHandle(Handle handle) {
return null;
}

private String checkConstant(Object cst) {
private String checkConstant(Object cst, boolean indy) {
if (cst instanceof Type) {
return checkType((Type) cst);
} else if (cst instanceof Handle) {
return checkHandle((Handle) cst);
return checkHandle((Handle) cst, indy);
}
return null;
}
Expand Down Expand Up @@ -453,14 +453,14 @@ public void visitMultiANewArrayInsn(String desc, int dims) {

@Override
public void visitLdcInsn(Object cst) {
reportMethodViolation(checkConstant(cst), "method body");
reportMethodViolation(checkConstant(cst, false), "method body");
}

@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) {
reportMethodViolation(checkHandle(bsm), "method body");
reportMethodViolation(checkHandle(bsm, true), "method body");
for (final Object cst : bsmArgs) {
reportMethodViolation(checkConstant(cst), "method body");
reportMethodViolation(checkConstant(cst, true), "method body");
}
}

Expand Down

0 comments on commit 4fca034

Please sign in to comment.