jamesfredley commented on code in PR #15956:
URL: https://github.com/apache/grails-core/pull/15956#discussion_r3591420256


##########
grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/UrlMappingsIndexProperties.java:
##########
@@ -0,0 +1,80 @@
+/*
+ *  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
+ *
+ *    https://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.grails.web.mapping;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Properties;
+
+/**
+ * Descriptor for a future build-time URL mappings index.
+ *
+ * @since 8.1
+ */
+public final class UrlMappingsIndexProperties {
+
+    public static final String LOCATION = 
"META-INF/grails/url-mappings-index.properties";
+
+    private static final UrlMappingsIndexProperties EMPTY = new 
UrlMappingsIndexProperties(false, new Properties());
+
+    private final boolean present;
+    private final Properties properties;
+
+    private UrlMappingsIndexProperties(boolean present, Properties properties) 
{
+        this.present = present;
+        this.properties = properties;
+    }
+
+    public static UrlMappingsIndexProperties load(ClassLoader classLoader) {
+        ClassLoader loader = classLoader == null ? 
Thread.currentThread().getContextClassLoader() : classLoader;
+        if (loader == null) {
+            return EMPTY;
+        }
+        try (InputStream inputStream = loader.getResourceAsStream(LOCATION)) {
+            if (inputStream == null) {
+                return EMPTY;
+            }
+            Properties properties = new Properties();
+            properties.load(inputStream);
+            return new UrlMappingsIndexProperties(true, properties);
+        }
+        catch (IOException e) {
+            throw new IllegalStateException("Unable to load " + LOCATION, e);
+        }
+    }

Review Comment:
   Addressed. `load(ClassLoader)` now tries the thread context classloader 
**first**, then falls back to the provided classloader, guarding for `null` 
(and a `SecurityException` from acquiring the TCCL). Failures are isolated 
**per loader**: an `IOException` *or* any non-fatal `RuntimeException` 
(including the `IllegalArgumentException` from malformed properties, and a 
restricted/throwing TCCL) is logged at debug and skips that loader, so a broken 
TCCL still falls through to the provided classloader; `EMPTY` is only returned 
after every loader has been tried, and `Error` is never swallowed. Added tests 
for the throwing-classloader (soft miss), malformed content, TCCL precedence, 
and valid-descriptor paths.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to