Skip to content

Commit 82e7271

Browse files
authored
Merge branch 'master' into kstat2
2 parents 91d8dd8 + 69bf22f commit 82e7271

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

CHANGES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Features
1313

1414
Bug Fixes
1515
---------
16-
16+
* [#1411](https://github.com/java-native-access/jna/pull/1411): Do not throw `Win32Exception` on success for empty section in `Kernel32Util#getPrivateProfileSection` - [@mkarg](https://github.com/mkarg).
1717

1818
Release 5.10.0
1919
==============

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ JNA is a mature library with dozens of contributors and hundreds of commercial a
3737
- [FileBot Media Renamer](http://www.filebot.net) by Reinhard Pointner.
3838
- [USB for Java](https://launchpad.net/libusb4j) by Mario Boikov.
3939
- [Waffle](https://github.com/dblock/waffle): Enables SSO on Windows in Java applications, by Daniel Doubrovkine.
40-
- [leveldb-jna](https://github.com/protonail/leveldb-jna): Cross-platform JNA based adapter for [LevelDB](https://github.com/google/leveldb) (used in [Keylord](http://protonail.com)).
41-
- [bolt-jna](https://github.com/protonail/bolt-jna): Cross-platform JNA based adapter for [Bolt](https://github.com/boltdb/bolt) (used in [Keylord](http://protonail.com)). It is show how to use JNA for binding to Go library.
40+
- [leveldb-jna](https://github.com/protonail/leveldb-jna): Cross-platform JNA based adapter for [LevelDB](https://github.com/google/leveldb).
41+
- [bolt-jna](https://github.com/protonail/bolt-jna): Cross-platform JNA based adapter for [Bolt](https://github.com/boltdb/bolt). It is to show how to use JNA for binding to Go library.
4242
- [JVM OpenVR Bindings](https://github.com/kotlin-graphics/openvr).
4343
- [Apache Ignite](https://ignite.apache.org/): Direct IO plugin
4444
- [Domino JNA](https://github.com/klehmann/domino-jna): Cross-platform access to HCL Notes/Domino C API methods from Java

contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ public static final SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX[] getLogicalProcesso
719719
return procInfoList.toArray(new SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX[0]);
720720
}
721721

722+
// Prevents useless heap pollution
723+
private static final String[] EMPTY_STRING_ARRAY = new String[0];
724+
722725
/**
723726
* Retrieves all the keys and values for the specified section of an initialization file.
724727
*
@@ -739,7 +742,12 @@ public static final SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX[] getLogicalProcesso
739742
public static final String[] getPrivateProfileSection(final String appName, final String fileName) {
740743
final char buffer[] = new char[32768]; // Maximum section size according to MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/ms724348(v=vs.85).aspx)
741744
if (Kernel32.INSTANCE.GetPrivateProfileSection(appName, buffer, new DWORD(buffer.length), fileName).intValue() == 0) {
742-
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
745+
final int lastError = Kernel32.INSTANCE.GetLastError();
746+
if (lastError == Kernel32.ERROR_SUCCESS) {
747+
return EMPTY_STRING_ARRAY;
748+
} else {
749+
throw new Win32Exception(lastError);
750+
}
743751
}
744752
return new String(buffer).split("\0");
745753
}

contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,18 @@ public final void testGetPrivateProfileSection() throws IOException {
244244
final File tmp = File.createTempFile("testGetPrivateProfileSection", ".ini");
245245
tmp.deleteOnExit();
246246

247-
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
247+
final PrintWriter writer0 = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
248+
try {
249+
writer0.println("[X]");
250+
} finally {
251+
writer0.close();
252+
}
253+
254+
final String[] lines0 = Kernel32Util.getPrivateProfileSection("X", tmp.getCanonicalPath());
255+
assertEquals(lines0.length, 0);
256+
257+
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp, true)));
248258
try {
249-
writer.println("[X]");
250259
writer.println("A=1");
251260
writer.println("foo=bar");
252261
} finally {

0 commit comments

Comments
 (0)