better handling of missing bytecodes
In some cases, class files will have non-abstract methods with no bytecodes (e.g., stubs for compilation purposes). While such a class file is invalid, we want to enable clients to handle such an error. With these changes, Shrike will throw an InvalidClassFileException for such cases, and WALA's IR construction code will throw a WalaRuntimeException.
This commit is contained in:
parent
6ed7b5a88e
commit
ba228963bf
BIN
com.ibm.wala.core.testdata/classes/CodeDeleted.class
Normal file
BIN
com.ibm.wala.core.testdata/classes/CodeDeleted.class
Normal file
Binary file not shown.
@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2008 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.core.tests.cha;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.core.tests.util.TestConstants;
|
||||
import com.ibm.wala.core.tests.util.WalaTestCase;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.WalaRuntimeException;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.io.FileProvider;
|
||||
|
||||
public class CodeDeletedTest extends WalaTestCase {
|
||||
|
||||
/**
|
||||
* Test handling of an invalid class where a non-abstract method has no code.
|
||||
* We want to throw an exception rather than crash.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ClassHierarchyException
|
||||
*/
|
||||
@Test(expected = WalaRuntimeException.class)
|
||||
public void testDeletedCode() throws IOException, ClassHierarchyException {
|
||||
AnalysisScope scope = null;
|
||||
scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA,
|
||||
(new FileProvider()).getFile("J2SEClassHierarchyExclusions.txt"), DupFieldsTest.class.getClassLoader());
|
||||
ClassHierarchy cha = ClassHierarchy.make(scope);
|
||||
TypeReference ref = TypeReference.findOrCreate(ClassLoaderReference.Application, "LCodeDeleted");
|
||||
IClass klass = cha.lookupClass(ref);
|
||||
AnalysisCache cache = new AnalysisCache();
|
||||
for (IMethod m : klass.getDeclaredMethods()) {
|
||||
if (m.toString().contains("foo")) {
|
||||
// should throw WalaRuntimeException
|
||||
cache.getIR(m);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -404,7 +404,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
|
||||
private void processBytecodesWithShrikeBT(BytecodeInfo info) throws InvalidClassFileException {
|
||||
info.decoder = makeDecoder();
|
||||
if (!isAbstract() && info.decoder == null) {
|
||||
Assertions.UNREACHABLE("bad method " + getReference());
|
||||
throw new InvalidClassFileException(-1, "non-abstract method " + getReference() + " has no bytecodes");
|
||||
}
|
||||
if (info.decoder == null) {
|
||||
return;
|
||||
|
||||
@ -23,7 +23,7 @@ import com.ibm.wala.ssa.SSAOptions;
|
||||
import com.ibm.wala.ssa.ShrikeIndirectionData;
|
||||
import com.ibm.wala.ssa.SymbolTable;
|
||||
import com.ibm.wala.ssa.analysis.DeadAssignmentElimination;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.WalaRuntimeException;
|
||||
|
||||
/**
|
||||
* An {@link IRFactory} that for methods that originate from Shrike.
|
||||
@ -45,8 +45,7 @@ public class ShrikeIRFactory implements IRFactory<IBytecodeMethod> {
|
||||
try {
|
||||
shrikeInstructions = method.getInstructions();
|
||||
} catch (InvalidClassFileException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
throw new WalaRuntimeException("bad method bytecodes", e);
|
||||
}
|
||||
final ShrikeCFG shrikeCFG = (ShrikeCFG) makeCFG(method, C);
|
||||
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2008 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.util;
|
||||
|
||||
/**
|
||||
* Runtime exception for some WALA failure.
|
||||
*
|
||||
*/
|
||||
public class WalaRuntimeException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* @param s a message describing the failure
|
||||
*/
|
||||
public WalaRuntimeException(String s, Throwable cause) {
|
||||
super(s, cause);
|
||||
}
|
||||
/**
|
||||
* @param string a message describing the failure
|
||||
*/
|
||||
public WalaRuntimeException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user