Skip to content

Commit

Permalink
Merge pull request #872 from amvanbaren/signature-download-nullpointer
Browse files Browse the repository at this point in the history
Handle download NullPointerException for migrations
  • Loading branch information
amvanbaren authored Mar 20, 2024
2 parents ce911e9 + f0e8769 commit 36f62b9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public void run(MigrationJobRequest jobRequest) throws Exception {
}

var entry = migrations.getDownload(extVersion);
if(entry == null) {
return;
}

try(var extensionFile = migrations.getExtensionFile(entry)) {
var download = entry.getKey();
var keyPair = repositories.findActiveKeyPair();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public void run(MigrationJobRequest jobRequest) throws Exception {

service.deleteResources(extVersion);
var entry = migrations.getDownload(extVersion);
if(entry == null) {
return;
}

var download = entry.getKey();
try(
var extensionFile = migrations.getExtensionFile(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@
* ****************************************************************************** */
package org.eclipse.openvsx.migration;

import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.eclipse.openvsx.entities.ExtensionVersion;
import org.eclipse.openvsx.entities.FileResource;
import org.eclipse.openvsx.entities.MigrationItem;
import org.eclipse.openvsx.repositories.RepositoryService;
import org.eclipse.openvsx.storage.AzureBlobStorageService;
import org.eclipse.openvsx.storage.GoogleCloudStorageService;
import org.eclipse.openvsx.storage.IStorageService;
import org.eclipse.openvsx.util.NamingUtil;
import org.eclipse.openvsx.util.TempFile;
import org.jobrunr.jobs.lambdas.JobRequestHandler;
import org.jobrunr.scheduling.JobRequestScheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -37,6 +40,8 @@
@Component
public class MigrationService {

protected final Logger logger = LoggerFactory.getLogger(MigrationService.class);

@Autowired
RestTemplate backgroundRestTemplate;

Expand Down Expand Up @@ -143,8 +148,13 @@ public FileResource getFileResource(ExtensionVersion extVersion, String type) {
@Transactional
public Map.Entry<FileResource, byte[]> getDownload(ExtensionVersion extVersion) {
var download = repositories.findFileByType(extVersion, FileResource.DOWNLOAD);
var content = download.getStorageType().equals(FileResource.STORAGE_DB) ? download.getContent() : null;
return new AbstractMap.SimpleEntry<>(download, content);
if(download != null) {
var content = download.getStorageType().equals(FileResource.STORAGE_DB) ? download.getContent() : null;
return new AbstractMap.SimpleEntry<>(download, content);
} else {
logger.warn("Could not find download for: {}", NamingUtil.toLogFormat(extVersion));
return null;
}
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@ConditionalOnProperty(value = "ovsx.data.mirror.enabled", havingValue = "false", matchIfMissing = true)
public class SetPreReleaseJobRequestHandler implements JobRequestHandler<MigrationJobRequest> {

protected final Logger logger = new JobRunrDashboardLogger(LoggerFactory.getLogger(ExtractResourcesJobRequestHandler.class));
protected final Logger logger = new JobRunrDashboardLogger(LoggerFactory.getLogger(SetPreReleaseJobRequestHandler.class));

@Autowired
MigrationService migrations;
Expand All @@ -36,8 +36,10 @@ public void run(MigrationJobRequest jobRequest) throws Exception {
var extVersions = service.getExtensionVersions(jobRequest, logger);
for(var extVersion : extVersions) {
var entry = migrations.getDownload(extVersion);
try (var extensionFile = migrations.getExtensionFile(entry)) {
service.updatePreviewAndPreRelease(extVersion, extensionFile);
if(entry != null) {
try (var extensionFile = migrations.getExtensionFile(entry)) {
service.updatePreviewAndPreRelease(extVersion, extensionFile);
}
}
}
}
Expand Down

0 comments on commit 36f62b9

Please sign in to comment.