@@ -29,82 +29,4 @@ public static ProtectionDomain createProtectionDomain(CodeSource codeSource, Cla
29
29
}
30
30
}
31
31
32
- private static final VarHandle PKG_MODULE_HANDLE ;
33
- static {
34
- try {
35
- // Obtain VarHandle for NamedPackage#module via trusted lookup
36
- var trustedLookupField = MethodHandles .Lookup .class .getDeclaredField ("IMPL_LOOKUP" );
37
- trustedLookupField .setAccessible (true );
38
- MethodHandles .Lookup trustedLookup = (MethodHandles .Lookup ) trustedLookupField .get (null );
39
-
40
- Class <?> namedPackage = Class .forName ("java.lang.NamedPackage" );
41
- PKG_MODULE_HANDLE = trustedLookup .findVarHandle (namedPackage , "module" , Module .class );
42
- } catch (Throwable t ) {
43
- throw new RuntimeException ("Error finding package module handle" , t );
44
- }
45
- }
46
-
47
- static void trySetPackageModule (Package pkg , Module module ) {
48
- // Ensure named packages are bound to their module of origin
49
- // Necessary for loading package-info classes
50
- Module value = (Module ) PKG_MODULE_HANDLE .get (pkg );
51
- if (value == null || !value .isNamed ()) {
52
- try {
53
- PKG_MODULE_HANDLE .set (pkg , module );
54
- } catch (Throwable t ) {
55
- throw new RuntimeException ("Error setting package module" , t );
56
- }
57
- }
58
- }
59
-
60
- static Package tryDefinePackage (final ClassLoader classLoader , String name , Manifest man , Function <String , Attributes > trustedEntries , Function <String [], Package > definePackage ) throws IllegalArgumentException
61
- {
62
- final var pname = name .substring (0 , name .lastIndexOf ('.' ));
63
- if (classLoader .getDefinedPackage (pname ) == null ) {
64
- synchronized (classLoader ) {
65
- if (classLoader .getDefinedPackage (pname ) != null ) return classLoader .getDefinedPackage (pname );
66
-
67
- String path = pname .replace ('.' , '/' ).concat ("/" );
68
- String specTitle = null , specVersion = null , specVendor = null ;
69
- String implTitle = null , implVersion = null , implVendor = null ;
70
-
71
- if (man != null ) {
72
- Attributes attr = trustedEntries .apply (path );
73
- if (attr != null ) {
74
- specTitle = attr .getValue (Attributes .Name .SPECIFICATION_TITLE );
75
- specVersion = attr .getValue (Attributes .Name .SPECIFICATION_VERSION );
76
- specVendor = attr .getValue (Attributes .Name .SPECIFICATION_VENDOR );
77
- implTitle = attr .getValue (Attributes .Name .IMPLEMENTATION_TITLE );
78
- implVersion = attr .getValue (Attributes .Name .IMPLEMENTATION_VERSION );
79
- implVendor = attr .getValue (Attributes .Name .IMPLEMENTATION_VENDOR );
80
- }
81
- attr = man .getMainAttributes ();
82
- if (attr != null ) {
83
- if (specTitle == null ) {
84
- specTitle = attr .getValue (Attributes .Name .SPECIFICATION_TITLE );
85
- }
86
- if (specVersion == null ) {
87
- specVersion = attr .getValue (Attributes .Name .SPECIFICATION_VERSION );
88
- }
89
- if (specVendor == null ) {
90
- specVendor = attr .getValue (Attributes .Name .SPECIFICATION_VENDOR );
91
- }
92
- if (implTitle == null ) {
93
- implTitle = attr .getValue (Attributes .Name .IMPLEMENTATION_TITLE );
94
- }
95
- if (implVersion == null ) {
96
- implVersion = attr .getValue (Attributes .Name .IMPLEMENTATION_VERSION );
97
- }
98
- if (implVendor == null ) {
99
- implVendor = attr .getValue (Attributes .Name .IMPLEMENTATION_VENDOR );
100
- }
101
- }
102
- }
103
- return definePackage .apply (new String []{pname , specTitle , specVersion , specVendor , implTitle , implVersion , implVendor });
104
- }
105
- } else {
106
- return classLoader .getDefinedPackage (pname );
107
- }
108
- }
109
-
110
32
}
0 commit comments