Skip to content

Commit 6706361

Browse files
Merge pull request #1570 from matthiasblaesing/cleanup
Integrate reported quality issues
2 parents 3656295 + 7775be3 commit 6706361

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/com/sun/jna/Function.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public static Function getFunction(Pointer p, int callFlags, String encoding) {
245245
this.library = library;
246246
this.functionName = functionName;
247247
this.callFlags = callFlags;
248-
this.options = library.options;
248+
this.options = library.getOptions();
249249
this.encoding = encoding != null ? encoding : Native.getDefaultStringEncoding();
250250
try {
251251
this.peer = library.getSymbolAddress(functionName);

src/com/sun/jna/NativeLibrary.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ public long getSymbolAddress(long handle, String name, SymbolProvider parent) {
9595
}
9696
};
9797

98-
private Cleaner.Cleanable cleanable;
99-
private long handle;
98+
private final Cleaner.Cleanable cleanable;
99+
private volatile long handle;
100100
private final String libraryName;
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
@@ -699,8 +701,8 @@ public void close() {
699701

700702
synchronized(this) {
701703
if (handle != 0) {
702-
cleanable.clean();
703704
handle = 0;
705+
cleanable.clean();
704706
}
705707
}
706708
}

0 commit comments

Comments
 (0)