sonatype-lift[bot] commented on code in PR #1458: URL: https://github.com/apache/solr/pull/1458#discussion_r1147706168
########## solr/core/src/java/org/apache/solr/handler/admin/api/InstallCoreDataAPI.java: ########## @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.solr.handler.admin.api; + +import static org.apache.solr.client.solrj.impl.BinaryResponseParser.BINARY_CONTENT_TYPE_V2; +import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.lang.invoke.MethodHandles; +import java.net.URI; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.solr.cloud.CloudDescriptor; +import org.apache.solr.cloud.ZkController; +import org.apache.solr.common.SolrException; +import org.apache.solr.core.CoreContainer; +import org.apache.solr.core.SolrCore; +import org.apache.solr.core.backup.repository.BackupRepository; +import org.apache.solr.handler.RestoreCore; +import org.apache.solr.handler.admin.CoreAdminHandler; +import org.apache.solr.jersey.JacksonReflectMapWriter; +import org.apache.solr.jersey.PermissionName; +import org.apache.solr.jersey.SolrJerseyResponse; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.SolrQueryResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * v2 implementation of the "Install Core Data" Core-Admin API + * + * <p>This is an internal API intended for use only by the Collection Admin "Install Shard Data" + * API. + */ +@Path("/cores/{coreName}/install") +public class InstallCoreDataAPI extends CoreAdminAPIBase { + + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + public InstallCoreDataAPI( + CoreContainer coreContainer, + CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker, + SolrQueryRequest req, + SolrQueryResponse rsp) { + super(coreContainer, coreAdminAsyncTracker, req, rsp); + } + + @POST + @Produces({"application/json", "application/xml", BINARY_CONTENT_TYPE_V2}) + @PermissionName(CORE_EDIT_PERM) + public SolrJerseyResponse installCoreData( + @PathParam("coreName") String coreName, InstallCoreDataRequestBody requestBody) + throws Exception { + final SolrJerseyResponse response = instantiateJerseyResponse(SolrJerseyResponse.class); + + if (requestBody == null) { + throw new SolrException( + SolrException.ErrorCode.BAD_REQUEST, "Required request body is missing"); + } + + final ZkController zkController = coreContainer.getZkController(); + if (zkController == null) { + throw new SolrException( + SolrException.ErrorCode.BAD_REQUEST, + "'Install Core Data' API only supported in SolrCloud clusters"); + } + + try (BackupRepository repository = coreContainer.newBackupRepository(requestBody.repository); + SolrCore core = coreContainer.getCore(coreName)) { + String location = repository.getBackupLocation(requestBody.location); + if (location == null) { + throw new SolrException( + SolrException.ErrorCode.BAD_REQUEST, + "'location' is not specified as a" + " parameter or as a default repository property"); + } + + final URI locationUri = repository.createDirectoryURI(location); + final CloudDescriptor cd = core.getCoreDescriptor().getCloudDescriptor(); Review Comment: <picture><img alt="15% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/15/display.svg"></picture> <b>*NULL_DEREFERENCE:</b>* object `core` last assigned on line 86 could be null and is dereferenced at line 95. --- <details><summary>âšī¸ Expand to see all <b>@sonatype-lift</b> commands</summary> You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings. | **Command** | **Usage** | | ------------- | ------------- | | `@sonatype-lift ignore` | Leave out the above finding from this PR | | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR | | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file | **Note:** When talking to LiftBot, you need to **refresh** the page to see its response. <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details> --- <b>Help us improve LIFT! (<i>Sonatype LiftBot external survey</i>)</b> Was this a good recommendation for you? <sub><small>Answering this survey will not impact your Lift settings.</small></sub> [â[đ Not relevant](https://www.sonatype.com/lift-comment-rating?comment=452568133&lift_comment_rating=1) â] - [â[đ Won't fix](https://www.sonatype.com/lift-comment-rating?comment=452568133&lift_comment_rating=2) â] - [â[đ Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=452568133&lift_comment_rating=3) â] - [â[đ Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=452568133&lift_comment_rating=4) â] - [â[đ Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=452568133&lift_comment_rating=5) â] -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org