Skip to content

Commit dabdcd7

Browse files
dbwiddisdblock
authored andcommitted
Deprecate EventLogRecord#getEventId in favor of #getInstanceId (#1105)
1 parent 65e43fb commit dabdcd7

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Next release (5.4.0)
77

88
Features
99
--------
10+
* [#1105](https://github.com/java-native-access/jna/issues/1105): Deprecate `c.s.j.p.win32.Advapi32Util.EventLogRecord#getEventId` in favor of `#getInstanceId` - [@dbwiddis](https://github.com/dbwiddis).
1011
* [#1097](https://github.com/java-native-access/jna/issues/1097): Allow `.ocx` as extension of native libraries on windows - [@dmigowski](https://github.com/dmigowski).
1112

1213
Bug Fixes

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.util.ArrayList;
5656
import java.util.HashMap;
5757
import java.util.Iterator;
58+
import java.util.List;
5859
import java.util.Map;
5960
import java.util.Map.Entry;
6061
import java.util.TreeMap;
@@ -92,7 +93,6 @@
9293
import com.sun.jna.ptr.LongByReference;
9394
import com.sun.jna.ptr.PointerByReference;
9495
import com.sun.jna.win32.W32APITypeMapper;
95-
import java.util.List;
9696

9797
/**
9898
* Advapi32 utility API.
@@ -2342,10 +2342,23 @@ public EVENTLOGRECORD getRecord() {
23422342
}
23432343

23442344
/**
2345-
* Event Id.
2345+
* The Instance ID, a resource identifier that corresponds to a string
2346+
* definition in the message resource file of the event source. The
2347+
* Event ID is the Instance ID with the top two bits masked off.
23462348
*
2347-
* @return Integer.
2349+
* @return An integer representing the 32-bit Instance ID.
2350+
*/
2351+
public int getInstanceId() {
2352+
return _record.EventID.intValue();
2353+
}
2354+
2355+
/**
2356+
* @deprecated As of 5.4.0, replaced by {@link #getInstanceId()}. The
2357+
* Event ID displayed in the Windows Event Viewer
2358+
* corresponds to {@link #getStatusCode()} for
2359+
* system-generated events.
23482360
*/
2361+
@Deprecated
23492362
public int getEventId() {
23502363
return _record.EventID.intValue();
23512364
}
@@ -2360,9 +2373,11 @@ public String getSource() {
23602373
}
23612374

23622375
/**
2363-
* Status code for the facility, part of the Event ID.
2376+
* Status code, the rightmost 16 bits of the Instance ID. Corresponds to
2377+
* the Event ID field in the Windows Event Viewer for system-generated
2378+
* events.
23642379
*
2365-
* @return Status code.
2380+
* @return An integer representing the low 16-bits of the Instance ID.
23662381
*/
23672382
public int getStatusCode() {
23682383
return _record.EventID.intValue() & 0xFFFF;

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
import com.sun.jna.Memory;
5656
import com.sun.jna.Native;
5757
import com.sun.jna.Pointer;
58+
import com.sun.jna.platform.win32.Advapi32Util.EventLogIterator;
59+
import com.sun.jna.platform.win32.Advapi32Util.EventLogRecord;
5860
import com.sun.jna.platform.win32.LMAccess.USER_INFO_1;
5961
import com.sun.jna.platform.win32.WinBase.FE_EXPORT_FUNC;
6062
import com.sun.jna.platform.win32.WinBase.FE_IMPORT_FUNC;
@@ -953,13 +955,29 @@ public void testReportEvent() {
953955
m.setByte(1, (byte) 2);
954956
m.setByte(2, (byte) 3);
955957
m.setByte(3, (byte) 4);
956-
assertTrue(Advapi32.INSTANCE.ReportEvent(h, WinNT.EVENTLOG_ERROR_TYPE, 0, 0, null, 2, 4, s, m));
958+
int eventId = 123 + 0x40000000;
959+
assertTrue(Advapi32.INSTANCE.ReportEvent(h, WinNT.EVENTLOG_ERROR_TYPE, 0, eventId, null, 2, 4, s, m));
957960
IntByReference after = new IntByReference();
958961
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, after));
959962
assertTrue(before.getValue() < after.getValue());
960963
assertFalse(h.equals(WinBase.INVALID_HANDLE_VALUE));
961964
assertTrue(Advapi32.INSTANCE.DeregisterEventSource(h));
962965
Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, jnaEventSourceRegistryPath);
966+
967+
// Test the event record
968+
EventLogIterator iter = new EventLogIterator(null, "Application", WinNT.EVENTLOG_BACKWARDS_READ);
969+
while (iter.hasNext()) {
970+
EventLogRecord record = iter.next();
971+
if (record.getRecord().EventID.getLow().intValue() == 123 && record.getStrings().length > 1
972+
&& "JNA".equals(record.getStrings()[0]) && "Event".equals(record.getStrings()[1])) {
973+
// Test Status Code stripping top 16 bits
974+
assertEquals(123, record.getStatusCode());
975+
// Test InstanceId
976+
assertEquals(123 | 0x40000000, record.getInstanceId());
977+
// Test Event ID stripping top 2 bits from InstanceId
978+
assertEquals(123, record.getInstanceId() & 0x3FFFFFFF);
979+
}
980+
}
963981
}
964982

965983
public void testGetNumberOfEventLogRecords() {

0 commit comments

Comments
 (0)