@@ -95,7 +95,7 @@ ModuleEntitlements defaultEntitlements(String componentName) {
9595 }
9696
9797 // pkg private for testing
98- ModuleEntitlements policyEntitlements (String componentName , List <Entitlement > entitlements ) {
98+ ModuleEntitlements policyEntitlements (String componentName , String moduleName , List <Entitlement > entitlements ) {
9999 FilesEntitlement filesEntitlement = FilesEntitlement .EMPTY ;
100100 for (Entitlement entitlement : entitlements ) {
101101 if (entitlement instanceof FilesEntitlement ) {
@@ -105,7 +105,7 @@ ModuleEntitlements policyEntitlements(String componentName, List<Entitlement> en
105105 return new ModuleEntitlements (
106106 componentName ,
107107 entitlements .stream ().collect (groupingBy (Entitlement ::getClass )),
108- FileAccessTree .of (filesEntitlement , pathLookup , List . of () )
108+ FileAccessTree .of (componentName , moduleName , filesEntitlement , pathLookup , exclusivePaths )
109109 );
110110 }
111111
@@ -150,7 +150,7 @@ private static Set<Module> findSystemModules() {
150150 * structures to indicate other modules aren't allowed to use these
151151 * files in {@link FileAccessTree}s.
152152 */
153- private final List <String > exclusivePaths ;
153+ private final List <ExclusivePath > exclusivePaths ;
154154
155155 public PolicyManager (
156156 Policy serverPolicy ,
@@ -170,15 +170,15 @@ public PolicyManager(
170170 this .apmAgentPackageName = apmAgentPackageName ;
171171 this .entitlementsModule = entitlementsModule ;
172172 this .pathLookup = requireNonNull (pathLookup );
173- this .defaultFileAccess = FileAccessTree .of (FilesEntitlement .EMPTY , pathLookup , List .of ());
173+ this .defaultFileAccess = FileAccessTree .of ("" , "" , FilesEntitlement .EMPTY , pathLookup , List .of ());
174174
175175 List <ExclusivePath > exclusivePaths = new ArrayList <>();
176176 for (var e : serverEntitlements .entrySet ()) {
177177 validateEntitlementsPerModule (SERVER_COMPONENT_NAME , e .getKey (), e .getValue ());
178178 buildExclusivePathList (exclusivePaths , pathLookup , SERVER_COMPONENT_NAME , e .getKey (), e .getValue ());
179179 }
180- validateEntitlementsPerModule (APM_AGENT_COMPONENT_NAME , "unnamed" , apmAgentEntitlements );
181- buildExclusivePathList (exclusivePaths , pathLookup , APM_AGENT_COMPONENT_NAME , "unnamed" , apmAgentEntitlements );
180+ validateEntitlementsPerModule (APM_AGENT_COMPONENT_NAME , ALL_UNNAMED , apmAgentEntitlements );
181+ buildExclusivePathList (exclusivePaths , pathLookup , APM_AGENT_COMPONENT_NAME , ALL_UNNAMED , apmAgentEntitlements );
182182 for (var p : pluginsEntitlements .entrySet ()) {
183183 for (var m : p .getValue ().entrySet ()) {
184184 validateEntitlementsPerModule (p .getKey (), m .getKey (), m .getValue ());
@@ -187,7 +187,7 @@ public PolicyManager(
187187 }
188188 exclusivePaths .sort (Comparator .comparing (ExclusivePath ::path ));
189189 validateExclusivePaths (exclusivePaths );
190- this .exclusivePaths = exclusivePaths . stream (). map ( ExclusivePath :: path ). toList () ;
190+ this .exclusivePaths = exclusivePaths ;
191191 }
192192
193193 private static Map <String , List <Entitlement >> buildScopeEntitlementsMap (Policy policy ) {
@@ -206,7 +206,7 @@ private static void validateEntitlementsPerModule(String componentName, String m
206206 }
207207 }
208208
209- private record ExclusivePath (String componentName , String moduleName , String path ) {}
209+ record ExclusivePath (String componentName , String moduleName , Path path ) {}
210210
211211 private static void buildExclusivePathList (
212212 List <ExclusivePath > exclusivePaths ,
@@ -221,8 +221,7 @@ private static void buildExclusivePathList(
221221 if (fd .exclusive ()) {
222222 List <Path > paths = fd .resolvePaths (pathLookup ).toList ();
223223 for (Path path : paths ) {
224- String pathStr = FileAccessTree .normalizePath (path );
225- exclusivePaths .add (new ExclusivePath (componentName , moduleName , pathStr ));
224+ exclusivePaths .add (new ExclusivePath (componentName , moduleName , path ));
226225 }
227226 }
228227 }
@@ -551,7 +550,7 @@ private ModuleEntitlements computeEntitlements(Class<?> requestingClass) {
551550
552551 if (requestingModule .isNamed () == false && requestingClass .getPackageName ().startsWith (apmAgentPackageName )) {
553552 // The APM agent is the only thing running non-modular in the system classloader
554- return policyEntitlements (APM_AGENT_COMPONENT_NAME , apmAgentEntitlements );
553+ return policyEntitlements (APM_AGENT_COMPONENT_NAME , ALL_UNNAMED , apmAgentEntitlements );
555554 }
556555
557556 return defaultEntitlements (UNKNOWN_COMPONENT_NAME );
@@ -566,7 +565,7 @@ private ModuleEntitlements getModuleScopeEntitlements(
566565 if (entitlements == null ) {
567566 return defaultEntitlements (componentName );
568567 }
569- return policyEntitlements (componentName , entitlements );
568+ return policyEntitlements (componentName , moduleName , entitlements );
570569 }
571570
572571 private static boolean isServerModule (Module requestingModule ) {
0 commit comments