Skip to content
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

Workarounds for null dereference bugs #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/clegoues/genprog4java/java/JavaStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ public Map<Expression, List<Expression>> getExtendableConditionalExpressions() {
if(extendableExpressions == null) {
extendableExpressions = new HashMap<Expression, List<Expression>>();
final MethodDeclaration md = (MethodDeclaration) ASTUtils.getEnclosingMethod(this.getASTNode());
if (md == null) {
return extendableExpressions;
}
final String methodName = md.getName().getIdentifier();
final List<Expression> replacements = JavaSemanticInfo.getConditionalExtensionExpressions(methodName, md);

Expand Down Expand Up @@ -389,6 +392,9 @@ public Map<Expression,List<Expression>> getReplacableMethodParameters() {
methodParamReplacements = new HashMap<Expression,List<Expression>>();

final MethodDeclaration md = (MethodDeclaration) ASTUtils.getEnclosingMethod(this.getASTNode());
if (md == null) {
return methodParamReplacements;
}
final String methodName = md.getName().getIdentifier();
final Set<String> namesInScopeHere = JavaSemanticInfo.inScopeAt(this);

Expand Down Expand Up @@ -492,6 +498,9 @@ public Map<ASTNode, List<List<ASTNode>>> getExtendableParameterMethods() {
extendableParameterMethods = new HashMap<ASTNode,List<List<ASTNode>>>();

final MethodDeclaration md = (MethodDeclaration) ASTUtils.getEnclosingMethod(this.getASTNode());
if (md == null) {
return extendableParameterMethods;
}
final String methodName = md.getName().getIdentifier();
final Set<String> namesInScopeHere = JavaSemanticInfo.inScopeAt(this);

Expand Down Expand Up @@ -599,6 +608,9 @@ public List<ASTNode> getIndexedCollectionObjects() {
public boolean visit(MethodInvocation node) {
Expression methodCall = node.getExpression();
SimpleName methodName = node.getName();
if(methodCall == null || methodName == null) {
return true;
}
switch(methodName.getIdentifier()) {
case "removeRange":
case "subList":
Expand Down
8 changes: 7 additions & 1 deletion src/clegoues/genprog4java/mut/edits/java/MethodReplacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;

Expand Down Expand Up @@ -34,7 +35,12 @@ public void edit(final ASTRewrite rewriter) {
SimpleName newMethodName = rewriter.getAST().newSimpleName(replaceWith.getName());
newNode.setName(newMethodName);

List<ASTNode> paramNodes = ((MethodInvocation) toReplace).arguments();
List<ASTNode> paramNodes;
if (toReplace instanceof SuperMethodInvocation) {
paramNodes = ((SuperMethodInvocation) toReplace).arguments();
} else {
paramNodes = ((MethodInvocation) toReplace).arguments();
}
for(ASTNode param : paramNodes) {
ASTNode newParam = rewriter.createCopyTarget(param);
newNode.arguments().add(newParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean visit(MethodInvocation node) {
SimpleName asExp = (SimpleName) arg;
ITypeBinding binding = asExp.resolveTypeBinding();

if(binding.isClass()) {
if(binding != null && binding.isClass()) {
SimpleName newVarName = myAST.newSimpleName(((SimpleName) arg).getIdentifier());
Assignment newAssignment = myAST.newAssignment();
newAssignment.setLeftHandSide(newVarName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void edit(final ASTRewrite rewriter) {
upperBoundCheck.setOperator(Operator.LESS);

SimpleName uqualifier = rewriter.getAST().newSimpleName(
((ArrayAccess) array).getArray().toString());
((ArrayAccess) array).getArray().toString().split("\\[")[0]);
SimpleName uname = rewriter.getAST().newSimpleName(
"length");
upperBoundCheck.setRightOperand(rewriter.getAST()
Expand Down