@@ -101,9 +101,9 @@ public long getSymbolAddress(long handle, String name, SymbolProvider parent) {
101101 private final String libraryPath ;
102102 private final Map <String , Function > functions = new HashMap <>();
103103 private final SymbolProvider symbolProvider ;
104- final int callFlags ;
105- private String encoding ;
106- final Map <String , ?> options ;
104+ private final int callFlags ;
105+ private final String encoding ;
106+ private final Map <String , ?> options ;
107107
108108 private static final Map <String , Reference <NativeLibrary >> libraries = new HashMap <>();
109109
@@ -120,6 +120,7 @@ private static String functionKey(String name, int flags, String encoding) {
120120 return name + "|" + flags + "|" + encoding ;
121121 }
122122
123+ @ SuppressWarnings ("LeakingThisInConstructor" )
123124 private NativeLibrary (String libraryName , String libraryPath , long handle , Map <String , ?> options ) {
124125 this .libraryName = getLibraryName (libraryName );
125126 this .libraryPath = libraryPath ;
@@ -129,17 +130,18 @@ private NativeLibrary(String libraryName, String libraryPath, long handle, Map<S
129130 int callingConvention = option instanceof Number ? ((Number )option ).intValue () : Function .C_CONVENTION ;
130131 this .callFlags = callingConvention ;
131132 this .options = options ;
132- this .encoding = (String )options .get (Library .OPTION_STRING_ENCODING );
133133 SymbolProvider optionSymbolProvider = (SymbolProvider )options .get (Library .OPTION_SYMBOL_PROVIDER );
134134 if (optionSymbolProvider == null ) {
135135 this .symbolProvider = NATIVE_SYMBOL_PROVIDER ;
136136 } else {
137137 this .symbolProvider = optionSymbolProvider ;
138138 }
139139
140- if (this .encoding == null ) {
141- this .encoding = Native .getDefaultStringEncoding ();
140+ String encodingValue = (String ) options .get (Library .OPTION_STRING_ENCODING );
141+ if (encodingValue == null ) {
142+ encodingValue = Native .getDefaultStringEncoding ();
142143 }
144+ this .encoding = encodingValue ;
143145
144146 // Special workaround for w32 kernel32.GetLastError
145147 // Short-circuit the function to use built-in GetLastError access
0 commit comments