sonatype-lift[bot] commented on code in PR #1302:
URL: https://github.com/apache/solr/pull/1302#discussion_r1081460073


##########
solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java:
##########
@@ -198,88 +198,94 @@ public ManagedIndexSchema create(
     this.loader = config.getResourceLoader();
     InputStream schemaInputStream = null;
 
-    if (null == resourceName) {
-      resourceName = IndexSchema.DEFAULT_SCHEMA_FILE;
-    }
-
-    int schemaZkVersion = -1;
-    if (!(loader instanceof ZkSolrResourceLoader)) {
-      schemaInputStream = readSchemaLocally();
-    } else { // ZooKeeper
-      final ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
-      final SolrZkClient zkClient = zkLoader.getZkController().getZkClient();
-      final String managedSchemaPath = lookupZKManagedSchemaPath();
-      managedSchemaResourceName =
-          managedSchemaPath.substring(managedSchemaPath.lastIndexOf("/") + 1); 
// not loving this
-      Stat stat = new Stat();
-      try {
-        // Attempt to load the managed schema
-        byte[] data = zkClient.getData(managedSchemaPath, null, stat, true);
-        schemaZkVersion = stat.getVersion();
-        schemaInputStream =
-            new ZkSolrResourceLoader.ZkByteArrayInputStream(data, 
managedSchemaPath, stat);
-        loadedResource = managedSchemaResourceName;
-        warnIfNonManagedSchemaExists();
-      } catch (InterruptedException e) {
-        // Restore the interrupted status
-        Thread.currentThread().interrupt();
-        log.warn("", e);
-      } catch (KeeperException.NoNodeException e) {
-        log.info(
-            "The schema is configured as managed, but managed schema resource 
{} not found - loading non-managed schema {} instead",
-            managedSchemaResourceName,
-            resourceName);
-      } catch (KeeperException e) {
-        String msg = "Error attempting to access " + managedSchemaPath;
-        log.error(msg, e);
-        throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
+    try {
+      if (null == resourceName) {
+        resourceName = IndexSchema.DEFAULT_SCHEMA_FILE;
       }
-      if (null == schemaInputStream) {
-        // The managed schema file could not be found - load the non-managed 
schema
+
+      int schemaZkVersion = -1;
+      if (!(loader instanceof ZkSolrResourceLoader)) {
+        schemaInputStream = readSchemaLocally();
+      } else { // ZooKeeper
+        final ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
+        final SolrZkClient zkClient = zkLoader.getZkController().getZkClient();
+        final String managedSchemaPath = lookupZKManagedSchemaPath();
+        managedSchemaResourceName =
+            managedSchemaPath.substring(managedSchemaPath.lastIndexOf("/") + 
1); // not loving this
+        Stat stat = new Stat();
         try {
-          schemaInputStream = loader.openResource(resourceName);
-          loadedResource = resourceName;
-          shouldUpgrade = true;
-        } catch (IOException e) {
+          // Attempt to load the managed schema
+          byte[] data = zkClient.getData(managedSchemaPath, null, stat, true);
+          schemaZkVersion = stat.getVersion();
+          schemaInputStream =
+              new ZkSolrResourceLoader.ZkByteArrayInputStream(data, 
managedSchemaPath, stat);
+          loadedResource = managedSchemaResourceName;
+          warnIfNonManagedSchemaExists();
+        } catch (InterruptedException e) {
+          // Restore the interrupted status
+          Thread.currentThread().interrupt();
+          log.warn("", e);
+        } catch (KeeperException.NoNodeException e) {
+          log.info(
+              "The schema is configured as managed, but managed schema 
resource {} not found - loading non-managed schema {} instead",
+              managedSchemaResourceName,
+              resourceName);
+        } catch (KeeperException e) {
+          String msg = "Error attempting to access " + managedSchemaPath;
+          log.error(msg, e);
+          throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
+        }
+        if (null == schemaInputStream) {
+          // The managed schema file could not be found - load the non-managed 
schema
           try {
-            // Retry to load the managed schema, in case it was created since 
the first attempt
-            byte[] data = zkClient.getData(managedSchemaPath, null, stat, 
true);
-            schemaZkVersion = stat.getVersion();
-            schemaInputStream = new ByteArrayInputStream(data);
-            loadedResource = managedSchemaPath;
-            warnIfNonManagedSchemaExists();
-          } catch (Exception e1) {
-            if (e1 instanceof InterruptedException) {
-              Thread.currentThread().interrupt(); // Restore the interrupted 
status
+            schemaInputStream = loader.openResource(resourceName);
+            loadedResource = resourceName;
+            shouldUpgrade = true;
+          } catch (IOException e) {
+            try {
+              // Retry to load the managed schema, in case it was created 
since the first attempt
+              byte[] data = zkClient.getData(managedSchemaPath, null, stat, 
true);
+              schemaZkVersion = stat.getVersion();
+              schemaInputStream = new ByteArrayInputStream(data);
+              loadedResource = managedSchemaPath;
+              warnIfNonManagedSchemaExists();
+            } catch (Exception e1) {
+              if (e1 instanceof InterruptedException) {
+                Thread.currentThread().interrupt(); // Restore the interrupted 
status
+              }
+              final String msg =
+                  "Error loading both non-managed schema '"
+                      + resourceName
+                      + "' and managed schema '"
+                      + managedSchemaResourceName
+                      + "'";
+              log.error(msg, e);
+              throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
msg, e);
             }
-            final String msg =
-                "Error loading both non-managed schema '"
-                    + resourceName
-                    + "' and managed schema '"
-                    + managedSchemaResourceName
-                    + "'";
-            log.error(msg, e);
-            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg, 
e);
           }
         }
       }
+      InputSource inputSource = new InputSource(schemaInputStream);
+      
inputSource.setSystemId(SystemIdResolver.createSystemIdFromResourceName(loadedResource));

Review Comment:
   <picture><img alt="7% of developers fix this issue" 
src="https://lift.sonatype.com/api/commentimage/fixrate/7/display.svg";></picture>
   
   đŸ’Ŧ 3 similar findings have been found in this PR
   
   ---
   
   *THREAD_SAFETY_VIOLATION:*  Read/Write race. Non-private method 
`ManagedIndexSchemaFactory.create(...)` reads without synchronization from 
`this.loadedResource`. Potentially races with write in method 
`ManagedIndexSchemaFactory.create(...)`.
    Reporting because this access may occur on a background thread.
   
   ---
   
   <details><summary><b>🔎 Expand here to view all instances of this 
finding</b></summary><br/>
     
     
   <div align=\"center\">
   
   
   | **File Path** | **Line Number** |
   | ------------- | ------------- |
   | solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java | 
[207](https://github.com/apache/solr/blob/cd4923ff78ae43d80b2b43029ff282e5322a8e13/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java#L207)
 |
   | solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java | 
[280](https://github.com/apache/solr/blob/cd4923ff78ae43d80b2b43029ff282e5322a8e13/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java#L280)
 |
   | solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java | 
[208](https://github.com/apache/solr/blob/cd4923ff78ae43d80b2b43029ff282e5322a8e13/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java#L208)
 |
   <p><a 
href="https://lift.sonatype.com/results/github.com/apache/solr/01GQ58R7X279C7SKRG4CCB9H9B?t=Infer|THREAD_SAFETY_VIOLATION"
 target="_blank">Visit the Lift Web Console</a> to find more details in your 
report.</p></div></details>
   
   
   
   ---
   
   <details><summary><b>ℹī¸ Learn about @sonatype-lift commands</b></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>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=370237930&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=370237930&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=370237930&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=370237930&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=370237930&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

Reply via email to