Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Structure.getFieldOrder() #183

Merged
merged 35 commits into from
Jan 25, 2013
Merged

Test Structure.getFieldOrder() #183

merged 35 commits into from
Jan 25, 2013

Conversation

bhamail
Copy link
Contributor

@bhamail bhamail commented Jan 24, 2013

We've seen a number of problems with missing or outdated Structure.getFieldOrder() implementations, so I put together a unit test (and reusable unit test utility class) that scans for Structure sub types and flags problematic getFieldOrder() implementations.

I used the "Reflections" library to do this, and put it's libs in a new "lib/test" sub folder (to keep them outta the distro).

Currently, the scan shows no problems in the core jna project, but there appear to be a number of problems (23) in the platform tree. If we commit this right now, the platform build will start failing due to these problems. I have pasted the output of these scans below. Maybe some of these are false alarms, but I'm pretty sure some of them are genuine problems.
Should we commit, and fix? Or fix, then commit?

Dan

java.lang.RuntimeException: Some Structure sub types (23) have problems with getFieldOrder(): 
com.sun.jna.platform.win32.WinUser$INPUT.getFieldOrder() [[type, input]] does not include declared field: INPUT_MOUSE; 
Could not instantiate Structure sub type: com.sun.jna.platform.win32.DBT$DEV_BROADCAST_HANDLE; 
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACE_HEADER must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
The Structure sub type: com.sun.jna.platform.win32.Sspi$TimeStamp must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
The Structure sub type: com.sun.jna.platform.unix.X11$XPointerMovedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_DENIED_ACE must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
The Structure sub type: com.sun.jna.platform.win32.Sspi$CtxtHandle must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
com.sun.jna.platform.win32.WinBase$FILETIME.getFieldOrder() [[dwLowDateTime, dwHighDateTime]] does not include declared field: EPOCH_DIFF; 
Parameterless constructor failed on Structure sub type: com.sun.jna.platform.win32.WinNT$TOKEN_PRIVILEGES; 
com.sun.jna.platform.win32.WinNT$SECURITY_DESCRIPTOR_RELATIVE.getFieldOrder() [[Revision, Sbz1, Control, Owner, Group, Sacl, Dacl]] does not include declared field: DACL; 
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonReleasedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
com.sun.jna.platform.win32.WinUser$KEYBDINPUT.getFieldOrder() [[wVk, wScan, dwFlags, time, dwExtraInfo]] does not include declared field: KEYEVENTF_EXTENDEDKEY; 
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusOutEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
The Structure sub type: com.sun.jna.platform.unix.X11$XLeaveWindowEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_ALLOWED_ACE must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
The Structure sub type: com.sun.jna.platform.win32.Sspi$CredHandle must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
Parameterless constructor failed on Structure sub type: com.sun.jna.platform.win32.WinGDI$RGNDATA; 
com.sun.jna.platform.win32.WinNT$ACL.getFieldOrder() [[AclRevision, Sbz1, AclSize, AceCount, Sbz2]] does not include declared field: ACEs; 
The Structure sub type: com.sun.jna.platform.unix.X11$XEnterWindowEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonPressedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
Could not instantiate Structure sub type: com.sun.jna.platform.win32.DBT$DEV_BROADCAST_PORT; 
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusInEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.; 
Could not instantiate Structure sub type: com.sun.jna.platform.win32.LMAccess$GROUP_INFO_3; 

    at com.sun.jna.StructureFieldOrderInspector.batchCheckStructureGetFieldOrder(StructureFieldOrderInspector.java:55)
    at com.sun.jna.platform.StructureFieldOrderTest.testMethodGetFieldOrder(StructureFieldOrderTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139)
    at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
'''

@twall
Copy link
Contributor

twall commented Jan 24, 2013

Dan,

Thanks for putting this together. A few notes:

  • missing getFieldOrder() declarations are mostly taken care of by the method being abstract. There are many derived structures that are simply aliases of the parent, which result in false positives in this list.
  • static fields should be ignored for purposes of getFieldOrder
  • unfortunately, JNA can only check the field order set accuracy at runtime; if you have good unit test coverage, this is sufficient, but for many it may not be

On Jan 24, 2013, at 2:49 AM, Dan Rollo wrote:

We've seen a number of problems with missing or outdated Structure.getFieldOrder() implementations, so I put together a unit test (and reusable unit test utility class) that scans for Structure sub types and flags problematic getFieldOrder() implementations.

I used the "Reflections" library to do this, and put it's libs in a new "lib/test" sub folder (to keep them outta the distro).

Currently, the scan shows no problems in the core jna project, but there appear to be a number of problems (23) in the platform tree. If we commit this right now, the platform build will start failing due to these problems. I have pasted the output of these scans below. Maybe some of these are false alarms, but I'm pretty sure some of them are genuine problems.
Should we commit, and fix? Or fix, then commit?

Dan

java.lang.RuntimeException: Some Structure sub types (23) have problems with getFieldOrder():
com.sun.jna.platform.win32.WinUser$INPUT.getFieldOrder() [[type, input]] does not include declared field: INPUT_MOUSE;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.DBT$DEV_BROADCAST_HANDLE;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACE_HEADER must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$TimeStamp must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XPointerMovedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_DENIED_ACE must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$CtxtHandle must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
com.sun.jna.platform.win32.WinBase$FILETIME.getFieldOrder() [[dwLowDateTime, dwHighDateTime]] does not include declared field: EPOCH_DIFF;
Parameterless constructor failed on Structure sub type: com.sun.jna.platform.win32.WinNT$TOKEN_PRIVILEGES;
com.sun.jna.platform.win32.WinNT$SECURITY_DESCRIPTOR_RELATIVE.getFieldOrder() [[Revision, Sbz1, Control, Owner, Group, Sacl, Dacl]] does not include declared field: DACL;
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonReleasedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
com.sun.jna.platform.win32.WinUser$KEYBDINPUT.getFieldOrder() [[wVk, wScan, dwFlags, time, dwExtraInfo]] does not include declared field: KEYEVENTF_EXTENDEDKEY;
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusOutEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XLeaveWindowEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_ALLOWED_ACE must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$CredHandle must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Parameterless constructor failed on Structure sub type: com.sun.jna.platform.win32.WinGDI$RGNDATA;
com.sun.jna.platform.win32.WinNT$ACL.getFieldOrder() [[AclRevision, Sbz1, AclSize, AceCount, Sbz2]] does not include declared field: ACEs;
The Structure sub type: com.sun.jna.platform.unix.X11$XEnterWindowEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonPressedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.DBT$DEV_BROADCAST_PORT;
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusInEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.LMAccess$GROUP_INFO_3;

at com.sun.jna.StructureFieldOrderInspector.batchCheckStructureGetFieldOrder(StructureFieldOrderInspector.java:55)
at com.sun.jna.platform.StructureFieldOrderTest.testMethodGetFieldOrder(StructureFieldOrderTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139)
at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

'''

You can merge this Pull Request by running

git pull https://github.com/bhamail/jna test-getFieldOrder
Or view, comment on, or merge it at:

#183

Commit Summary

• Add test utility to scan for Structure.getFieldOrder() issues.
• testToScanForGetFieldOrderIssues
• remove unneeded cast
• add helper method
• add jna test classes to test classpath so we can use StructureFieldOrder scanner.
• remove stale imports
• add jna test classes to test classpath so we can use StructureFieldOrder scanner.
• try adding reflections test libs via *.jar pattern.
• try adding reflections test lib file name pattern.
• try adding reflections test libs via file name pattern.
• handle inaccessible getFieldOrder() method.
• allow user supplied list of classes for which to ignore constructor errors.
• add batch version of check method
• change ignore constructor error list to be list of classname prefixes. allows for ignoring all inner classes of a given class.
• add unit test to platform project to scan for Structure.getFieldOrder() problems.
File Changes

• M build.xml (1)
• M contrib/platform/nbproject/project.properties (125)
• A contrib/platform/test/com/sun/jna/platform/StructureFieldOrderTest.java (37)
• A lib/test/dom4j-1.6.1.jar (0)
• A lib/test/guava-11.0.2.jar (0)
• A lib/test/javassist-3.12.1.GA.jar (0)
• A lib/test/reflections-0.9.8.jar (0)
• A lib/test/slf4j-api-1.6.1.jar (0)
• A test/com/sun/jna/StructureFieldOrderInspector.java (179)
• A test/com/sun/jna/StructureFieldOrderInspectorTest.java (112)
Patch Links:

https://github.com/twall/jna/pull/183.patch
https://github.com/twall/jna/pull/183.diff

@twall
Copy link
Contributor

twall commented Jan 24, 2013

I've checked through these, and the only warnings that don't refer to a subclass alias or a non-public or static member field are the DBT$DEV_BROADCAST_HANDLE, DBT$DEV_BROADCAST_PORT, and GROUP_INFO_3.

I think any patches should be made as part of this PR.

On Jan 24, 2013, at 2:49 AM, Dan Rollo wrote:

We've seen a number of problems with missing or outdated Structure.getFieldOrder() implementations, so I put together a unit test (and reusable unit test utility class) that scans for Structure sub types and flags problematic getFieldOrder() implementations.

I used the "Reflections" library to do this, and put it's libs in a new "lib/test" sub folder (to keep them outta the distro).

Currently, the scan shows no problems in the core jna project, but there appear to be a number of problems (23) in the platform tree. If we commit this right now, the platform build will start failing due to these problems. I have pasted the output of these scans below. Maybe some of these are false alarms, but I'm pretty sure some of them are genuine problems.
Should we commit, and fix? Or fix, then commit?

Dan

java.lang.RuntimeException: Some Structure sub types (23) have problems with getFieldOrder():
com.sun.jna.platform.win32.WinUser$INPUT.getFieldOrder() [[type, input]] does not include declared field: INPUT_MOUSE;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.DBT$DEV_BROADCAST_HANDLE;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACE_HEADER must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$TimeStamp must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XPointerMovedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_DENIED_ACE must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$CtxtHandle must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
com.sun.jna.platform.win32.WinBase$FILETIME.getFieldOrder() [[dwLowDateTime, dwHighDateTime]] does not include declared field: EPOCH_DIFF;
Parameterless constructor failed on Structure sub type: com.sun.jna.platform.win32.WinNT$TOKEN_PRIVILEGES;
com.sun.jna.platform.win32.WinNT$SECURITY_DESCRIPTOR_RELATIVE.getFieldOrder() [[Revision, Sbz1, Control, Owner, Group, Sacl, Dacl]] does not include declared field: DACL;
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonReleasedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
com.sun.jna.platform.win32.WinUser$KEYBDINPUT.getFieldOrder() [[wVk, wScan, dwFlags, time, dwExtraInfo]] does not include declared field: KEYEVENTF_EXTENDEDKEY;
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusOutEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XLeaveWindowEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_ALLOWED_ACE must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$CredHandle must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Parameterless constructor failed on Structure sub type: com.sun.jna.platform.win32.WinGDI$RGNDATA;
com.sun.jna.platform.win32.WinNT$ACL.getFieldOrder() [[AclRevision, Sbz1, AclSize, AceCount, Sbz2]] does not include declared field: ACEs;
The Structure sub type: com.sun.jna.platform.unix.X11$XEnterWindowEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonPressedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.DBT$DEV_BROADCAST_PORT;
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusInEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.LMAccess$GROUP_INFO_3;

at com.sun.jna.StructureFieldOrderInspector.batchCheckStructureGetFieldOrder(StructureFieldOrderInspector.java:55)
at com.sun.jna.platform.StructureFieldOrderTest.testMethodGetFieldOrder(StructureFieldOrderTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139)
at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

'''

You can merge this Pull Request by running

git pull https://github.com/bhamail/jna test-getFieldOrder
Or view, comment on, or merge it at:

#183

Commit Summary

• Add test utility to scan for Structure.getFieldOrder() issues.
• testToScanForGetFieldOrderIssues
• remove unneeded cast
• add helper method
• add jna test classes to test classpath so we can use StructureFieldOrder scanner.
• remove stale imports
• add jna test classes to test classpath so we can use StructureFieldOrder scanner.
• try adding reflections test libs via *.jar pattern.
• try adding reflections test lib file name pattern.
• try adding reflections test libs via file name pattern.
• handle inaccessible getFieldOrder() method.
• allow user supplied list of classes for which to ignore constructor errors.
• add batch version of check method
• change ignore constructor error list to be list of classname prefixes. allows for ignoring all inner classes of a given class.
• add unit test to platform project to scan for Structure.getFieldOrder() problems.
File Changes

• M build.xml (1)
• M contrib/platform/nbproject/project.properties (125)
• A contrib/platform/test/com/sun/jna/platform/StructureFieldOrderTest.java (37)
• A lib/test/dom4j-1.6.1.jar (0)
• A lib/test/guava-11.0.2.jar (0)
• A lib/test/javassist-3.12.1.GA.jar (0)
• A lib/test/reflections-0.9.8.jar (0)
• A lib/test/slf4j-api-1.6.1.jar (0)
• A test/com/sun/jna/StructureFieldOrderInspector.java (179)
• A test/com/sun/jna/StructureFieldOrderInspectorTest.java (112)
Patch Links:

https://github.com/twall/jna/pull/183.patch
https://github.com/twall/jna/pull/183.diff

@twall
Copy link
Contributor

twall commented Jan 24, 2013

Can you re-format this PR so that it's a branch-to-master PR on the jna repo (instead of from your private one)? or you can just apply the following diff to yours and the PR will update automatically. This diff addresses the missing default constructor warnings.

diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java b/contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java
index 1c31ae2..177c671 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/WinGDI.java
@@ -47,6 +47,9 @@ public interface WinGDI extends StdCallLibrary {
             return Arrays.asList(new String[] { "rdh", "Buffer" });
         }

+        public RGNDATA() { 
+            this(1); 
+        }
         public RGNDATA(int bufferSize) {
             Buffer = new byte[bufferSize];
             allocateMemory();
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
index 997d712..f20ff87 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
@@ -470,6 +470,10 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {
             return Arrays.asList(new String[] { "PrivilegeCount", "Privileges" });
         }

+        /** Creates an empty instance with no privileges. */
+        public TOKEN_PRIVILEGES() {
+            this(0);
+        }
         /**
          * @param nbOfPrivileges
          *            Desired size of the Privileges array
@@ -478,6 +482,15 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {
             PrivilegeCount = new DWORD(nbOfPrivileges);
             Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges];
         }
+
+        /** Initialize a TOKEN_PRIVILEGES instance from initialized memory. */
+        public TOKEN_PRIVILEGES(Pointer p) {
+            super(p);
+            int count = p.getInt(0);
+            PrivilegeCount = new DWORD(count);
+            Privileges = new LUID_AND_ATTRIBUTES[count];
+            read();
+        }
     }

     /**
@@ -1994,7 +2007,7 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {
         public short AceCount;
         public short Sbz2;

-        ACCESS_ACEStructure[] ACEs;
+        private ACCESS_ACEStructure[] ACEs;

         public ACCESS_ACEStructure[] getACEStructures() {
             return ACEs;
@@ -2029,8 +2042,8 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {
             setDacl();
         }

-        public SECURITY_DESCRIPTOR_RELATIVE(Memory memory) {
-            super(memory);
+        public SECURITY_DESCRIPTOR_RELATIVE(Pointer p) {
+            super(p);
             setDacl();
         }

@@ -2053,6 +2066,7 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {

         PSID psid;

+        public ACEStructure() { }
         public ACEStructure(Pointer p) {
             super(p);
         }
@@ -2072,6 +2086,7 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {

     /* ACE header */
     public static class ACE_HEADER extends ACEStructure {
+        public ACE_HEADER() { }
         public ACE_HEADER(Pointer p) {
             super(p);
             read();
@@ -2087,6 +2102,7 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {
             list.addAll(Arrays.asList(new String[] { "Mask", "SidStart"}));
             return list;
         }
+        public ACCESS_ACEStructure() { }
         public ACCESS_ACEStructure(Pointer p) {
             super(p);
             read();
@@ -2109,6 +2125,7 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {

     /* Access allowed ACE */
     public static class ACCESS_ALLOWED_ACE extends ACCESS_ACEStructure {
+        public ACCESS_ALLOWED_ACE() { }
         public ACCESS_ALLOWED_ACE(Pointer p) {
             super(p);
         }
@@ -2116,6 +2133,7 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD {

     /* Access denied ACE */
     public static class ACCESS_DENIED_ACE extends ACCESS_ACEStructure {
+        public ACCESS_DENIED_ACE() { }
         public ACCESS_DENIED_ACE(Pointer p) {
             super(p);
         }

@wolftobias
Copy link
Contributor

I`ve checked the classes DEV_BROADCAST_HANDLE and DEV_BROADCAST_PORT and
they seems to have a correct getFieldOder implementation.


Von: twall [mailto:[email protected]]
Gesendet: 24 January 2013 12:25
An: twall/jna
Betreff: Re: [jna] Test Structure.getFieldOrder() (#183)

I've checked through these, and the only warnings that don't refer to a
subclass alias or a non-public or static member field are the
DBT$DEV_BROADCAST_HANDLE, DBT$DEV_BROADCAST_PORT, and GROUP_INFO_3.

I think any patches should be made as part of this PR.

On Jan 24, 2013, at 2:49 AM, Dan Rollo wrote:

We've seen a number of problems with missing or outdated
Structure.getFieldOrder() implementations, so I put together a unit test
(and reusable unit test utility class) that scans for Structure sub types
and flags problematic getFieldOrder() implementations.

I used the "Reflections" library to do this, and put it's libs in a new
"lib/test" sub folder (to keep them outta the distro).

Currently, the scan shows no problems in the core jna project, but there
appear to be a number of problems (23) in the platform tree. If we commit
this right now, the platform build will start failing due to these problems.
I have pasted the output of these scans below. Maybe some of these are false
alarms, but I'm pretty sure some of them are genuine problems.
Should we commit, and fix? Or fix, then commit?

Dan

java.lang.RuntimeException: Some Structure sub types (23) have problems
with getFieldOrder():
com.sun.jna.platform.win32.WinUser$INPUT.getFieldOrder() [[type, input]]
does not include declared field: INPUT_MOUSE;
Could not instantiate Structure sub type:
com.sun.jna.platform.win32.DBT$DEV_BROADCAST_HANDLE;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACE_HEADER must
define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$TimeStamp must
define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XPointerMovedEvent
must define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_DENIED_ACE
must define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$CtxtHandle must
define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
com.sun.jna.platform.win32.WinBase$FILETIME.getFieldOrder()
[[dwLowDateTime, dwHighDateTime]] does not include declared field:
EPOCH_DIFF;
Parameterless constructor failed on Structure sub type:
com.sun.jna.platform.win32.WinNT$TOKEN_PRIVILEGES;

com.sun.jna.platform.win32.WinNT$SECURITY_DESCRIPTOR_RELATIVE.getFieldOrder(
) [[Revision, Sbz1, Control, Owner, Group, Sacl, Dacl]] does not include
declared field: DACL;
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonReleasedEvent
must define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
com.sun.jna.platform.win32.WinUser$KEYBDINPUT.getFieldOrder() [[wVk,
wScan, dwFlags, time, dwExtraInfo]] does not include declared field:
KEYEVENTF_EXTENDEDKEY;
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusOutEvent must
define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XLeaveWindowEvent
must define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
The Structure sub type:
com.sun.jna.platform.win32.WinNT$ACCESS_ALLOWED_ACE must define the method:
getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;

The Structure sub type: com.sun.jna.platform.win32.Sspi$CredHandle must
define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
Parameterless constructor failed on Structure sub type:
com.sun.jna.platform.win32.WinGDI$RGNDATA;
com.sun.jna.platform.win32.WinNT$ACL.getFieldOrder() [[AclRevision, Sbz1,
AclSize, AceCount, Sbz2]] does not include declared field: ACEs;
The Structure sub type: com.sun.jna.platform.unix.X11$XEnterWindowEvent
must define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonPressedEvent
must define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
Could not instantiate Structure sub type:
com.sun.jna.platform.win32.DBT$DEV_BROADCAST_PORT;
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusInEvent must
define the method: getFieldOrder(). See the javadoc for
Structure.getFieldOrder() for details.;
Could not instantiate Structure sub type:
com.sun.jna.platform.win32.LMAccess$GROUP_INFO_3;

at
com.sun.jna.StructureFieldOrderInspector.batchCheckStructureGetFieldOrder(St
ructureFieldOrderInspector.java:55)
at
com.sun.jna.platform.StructureFieldOrderTest.testMethodGetFieldOrder(Structu
reFieldOrderTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at
com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139
)
at
com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestR
unner.java:52)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitSta
rter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
'''

You can merge this Pull Request by running

git pull https://github.com/bhamail/jna test-getFieldOrder
Or view, comment on, or merge it at:

#183

Commit Summary

. Add test utility to scan for Structure.getFieldOrder() issues.
. testToScanForGetFieldOrderIssues
. remove unneeded cast
. add helper method
. add jna test classes to test classpath so we can use StructureFieldOrder
scanner.
. remove stale imports
. add jna test classes to test classpath so we can use StructureFieldOrder
scanner.
. try adding reflections test libs via *.jar pattern.
. try adding reflections test lib file name pattern.
. try adding reflections test libs via file name pattern.
. handle inaccessible getFieldOrder() method.
. allow user supplied list of classes for which to ignore constructor
errors.
. add batch version of check method
. change ignore constructor error list to be list of classname prefixes.
allows for ignoring all inner classes of a given class.
. add unit test to platform project to scan for Structure.getFieldOrder()
problems.
File Changes

. M build.xml (1)
. M contrib/platform/nbproject/project.properties (125)
. A
contrib/platform/test/com/sun/jna/platform/StructureFieldOrderTest.java (37)

. A lib/test/dom4j-1.6.1.jar (0)
. A lib/test/guava-11.0.2.jar (0)
. A lib/test/javassist-3.12.1.GA.jar (0)
. A lib/test/reflections-0.9.8.jar (0)
. A lib/test/slf4j-api-1.6.1.jar (0)
. A test/com/sun/jna/StructureFieldOrderInspector.java (179)
. A test/com/sun/jna/StructureFieldOrderInspectorTest.java (112)
Patch Links:

. https://github.com/twall/jna/pull/183.patch
. https://github.com/twall/jna/pull/183.diff

Reply to this email directly or view it on
#183 (comment) GitHub.

<https://github.com/notifications/beacon/Jshd8sI44GVrKZBvymxqKIcbr1qTlzgkagz
BvG5PKvUDOEsvILCv3LsHbYcBUHaT.gif>

@bhamail
Copy link
Contributor Author

bhamail commented Jan 25, 2013

Ugh. Looks like git config for core.autocrlf ("input") did badness to the windows line endings. changed core.autocrlf setting to "false", cleared local cache and reset local head, and things seem to be behaving better now.

bhamail added a commit that referenced this pull request Jan 25, 2013
Test Structure.getFieldOrder()

All Structure warnings are solved, so I'm going to commit this.

BTW, I saw something odd ("has unknown size" error) when instantiating an empty Structure (one with no instance fields). Please see the @todo comments in com.sun.jna.StructureFieldOrderInspectorTest.java. Restore the test: testCheckMethodGetFieldOrderStaticFieldOnlyStatic() to reproduce the behavior.
@bhamail bhamail merged commit d9fb94a into java-native-access:master Jan 25, 2013
mstyura pushed a commit to mstyura/jna that referenced this pull request Sep 9, 2024
Motivation:

At the moment we dont provide a lot of details in the SSLHandshakeException which makes it hard to understand why a handshake fails.

Modifications:

- Add native method which will peek into the error queue and provide more details if possible
- Use these details when constructing the exception message

Result:

Easier to debug SSLHandshakeException causes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants