Skip to content

Commit

Permalink
fix: should check if the analysis target exists
Browse files Browse the repository at this point in the history
  • Loading branch information
D-D-H committed Mar 23, 2024
1 parent f10ce0a commit eb0063f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -171,6 +171,7 @@ public boolean test(byte[] bytes) {

@Override
public boolean needOptionsForAnalysis(Path target) {
checkExists(target);
return !indexFile(target).exists() && !errorLogFile(target).exists() && !isActive(target);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public boolean test(byte[] bytes) {

@Override
public boolean needOptionsForAnalysis(Path target) {
checkExists(target);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -26,6 +26,7 @@
import org.eclipse.jifa.analysis.listener.ProgressListener;
import org.eclipse.jifa.analysis.support.MethodNameConverter;
import org.eclipse.jifa.analysis.util.TypeParameterUtil;
import org.eclipse.jifa.common.domain.exception.ErrorCodeException;
import org.eclipse.jifa.common.util.ExecutorFactory;
import org.eclipse.jifa.common.util.Validate;

Expand All @@ -51,6 +52,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.eclipse.jifa.analysis.enums.AnalysisErrorCode.FILE_NOT_FOUND;
import static org.eclipse.jifa.analysis.listener.ProgressListener.NoOpProgressListener;

@Slf4j
Expand Down Expand Up @@ -272,6 +274,7 @@ private Class<Analyzer> analyzerClass() {
}

public boolean needOptionsForAnalysis(@ApiParameterMeta(targetPath = true) Path target) {
checkExists(target);
return false;
}

Expand All @@ -280,6 +283,9 @@ public final void analyze(@ApiParameterMeta(targetPath = true) Path target,
if (cachedAnalyzer.getIfPresent(target) != null) {
return;
}

checkExists(target);

ProgressListener progressListener = new DefaultProgressListener();

boolean puttedByMe = buildingAnalyzerListeners.putIfAbsent(target, progressListener) == null;
Expand Down Expand Up @@ -308,7 +314,7 @@ public final void analyze(@ApiParameterMeta(targetPath = true) Path target,
}
}

public Progress progressOfAnalysis(@ApiParameterMeta(targetPath = true) Path target) throws IOException {
public final Progress progressOfAnalysis(@ApiParameterMeta(targetPath = true) Path target) throws IOException {
if (cachedAnalyzer.getIfPresent(target) != null) {
Progress progress = new Progress();
progress.setPercent(1);
Expand All @@ -323,6 +329,7 @@ public Progress progressOfAnalysis(@ApiParameterMeta(targetPath = true) Path tar
progress.setPercent(listener.percent());
return progress;
}
checkExists(target);
Progress result = new Progress();
result.setState(Progress.State.FAILURE);
File errorLog = errorLogFile(target);
Expand Down Expand Up @@ -365,6 +372,12 @@ protected int getCacheDuration() {
return 8;
}

protected void checkExists(Path target) {
if (!target.toFile().exists()) {
throw new ErrorCodeException(FILE_NOT_FOUND);
}
}

private void cleanAndDisposeAnalyzerCache(Path target) {
// Dispose snapshot synchronized to prevent from some problem caused by data inconsistency.
Analyzer analyzer = cachedAnalyzer.getIfPresent(target);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.analysis.enums;

import org.eclipse.jifa.common.domain.exception.ErrorCode;

public enum AnalysisErrorCode implements ErrorCode {

FILE_NOT_FOUND("File not found"),
;

private final String message;

AnalysisErrorCode(String message) {
this.message = message;
}

@Override
public String message() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ private static ErrorCode getErrorCodeOf(Throwable throwable) {
if (throwable instanceof MissingServletRequestParameterException || throwable instanceof IllegalArgumentException) {
return CommonErrorCode.ILLEGAL_ARGUMENT;
}
while ((throwable = throwable.getCause()) != null) {
if (throwable instanceof ErrorCodeAccessor errorCodeAccessor) {
return errorCodeAccessor.getErrorCode();
}
}
return CommonErrorCode.INTERNAL_ERROR;
}

Expand Down

0 comments on commit eb0063f

Please sign in to comment.