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

Java beans Introspector causes segfault #522

Closed
dsyer opened this issue Jul 5, 2018 · 4 comments
Closed

Java beans Introspector causes segfault #522

dsyer opened this issue Jul 5, 2018 · 4 comments
Assignees

Comments

@dsyer
Copy link

dsyer commented Jul 5, 2018

This code:

public class Introspectors {

	public static void main(String[] args) throws Exception {
		new Introspectors().run();
	}

	private void run() throws Exception {
		PropertyDescriptor[] pds = Introspector.getBeanInfo(Bar.class)
				.getPropertyDescriptors();
		for (PropertyDescriptor pd : pds) {
			System.err.println("Property: " + pd);
		}
	}

}

runs fine as a normal Java program. As a native image it blows big chunks:

$ cat reflect.json
[
  {
      "name" : "Bar",
      "allPublicFields": true,
      "allPublicMethods": true,
      "allDeclaredMethods": true,
      "allDeclaredFields": true
  }
]
$ native-image -H:Name=intro -H:ReflectionConfigurationFiles=reflect.json -H:+ReportUnsupportedElementsAtRuntime  -cp target/classes/:target/graal-test-0.0.1-SNAPSHOT-shaded.jar Introspectors
./intro
...
Full Stacktrace:

  
  RSP 00007ffca0b377c0 RIP 00000000004b8230  [image code] java.lang.reflect.Method.getTypeParameters(Method.java:214)
  RSP 00007ffca0b377e0 RIP 00000000004b6230  [image code] java.lang.reflect.Executable.sharedToGenericString(Executable.java:148)
  RSP 00007ffca0b37860 RIP 00000000004b87af  [image code] java.lang.reflect.Method.toGenericString(Method.java:415)
  RSP 00007ffca0b37880 RIP 000000000046ce4f  [image code] java.beans.MethodRef.set(MethodRef.java:46)
  RSP 00007ffca0b378b0 RIP 000000000046be92  [image code] java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:117)
  RSP 00007ffca0b378e0 RIP 000000000046b568  [image code] java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72)
  RSP 00007ffca0b37900 RIP 00000000004650cf  [image code] java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56)
  RSP 00007ffca0b37900 RIP 00000000004650cf  [image code] java.beans.Introspector.getTargetMethodInfo(Introspector.java:1205)
  RSP 00007ffca0b37950 RIP 0000000000461321  [image code] java.beans.Introspector.getBeanInfo(Introspector.java:426)
  RSP 00007ffca0b379b0 RIP 0000000000461551  [image code] java.beans.Introspector.getBeanInfo(Introspector.java:173)
  RSP 00007ffca0b37a00 RIP 0000000000461800  [image code] java.beans.Introspector.getBeanInfo(Introspector.java:260)
  RSP 00007ffca0b37a30 RIP 000000000045f41d  [image code] java.beans.Introspector.<init>(Introspector.java:407)
  RSP 00007ffca0b37a80 RIP 0000000000461543  [image code] java.beans.Introspector.getBeanInfo(Introspector.java:173)
  RSP 00007ffca0b37ad0 RIP 0000000000403018  [image code] Introspectors.run(Introspectors.java:11)
  RSP 00007ffca0b37b40 RIP 00000000004518e9  [image code] Introspectors.main(Introspectors.java:7)
  RSP 00007ffca0b37b40 RIP 00000000004518e9  [image code] com.oracle.svm.reflect.proxies.Proxy_1_Introspectors_main.invoke(Unknown Source)
  RSP 00007ffca0b37b80 RIP 00000000004b843d  [image code] java.lang.reflect.Method.invoke(Method.java:498)
  RSP 00007ffca0b37bc0 RIP 00000000004036b3  [image code] com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:173)
  RSP 00007ffca0b37c10 RIP 00000000004092e3  [image code] com.oracle.svm.core.code.CEntryPointCallStubs.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
  
Use runtime option -R:-InstallSegfaultHandler if you don't want to use SubstrateSegfaultHandler.

Bye bye ...

It might be interesting that without the JSON configuration the program runs successfully, but doesn't detect any property descriptors.

@dsyer
Copy link
Author

dsyer commented Jul 5, 2018

Doing some more research here it seems that the problem is that introspecting the getClass() method causes this exception. If you avoid that method you can step around the problem, but I don't think that's an option with Introspectors in the standard Open JDK libraries.

@cstancu cstancu self-assigned this Jul 5, 2018
@dsyer
Copy link
Author

dsyer commented Jul 5, 2018

Here's another data point. This simple program fails at runtime as a native image in the same way as above:

public class PropertyDescriptors {

	public void setBar(Bar bar) {
	}

	public void setConverters(List<Bar> converters) {
	}

	public static void main(String[] args) throws Exception {
		new PropertyDescriptors().run();
	}

	private void run() throws Exception {
		PropertyDescriptor[] pds = new PropertyDescriptor[] {
				new PropertyDescriptor("bar", null,
						PropertyDescriptors.class.getMethod("setBar", Bar.class)),
				new PropertyDescriptor("converters", null, PropertyDescriptors.class
						.getMethod("setConverters", List.class)) };
		for (PropertyDescriptor pd : pds) {
			System.err.println("Property: " + pd);
		}
	}

}

If you omit the "converters" property, or make it just a plain List it works fine, so it seems like it's something connected with the generic signature of the setter?

@cstancu cstancu added the bug label Jul 23, 2018
dsyer pushed a commit to dsyer/graal-issues that referenced this issue Apr 1, 2019
property-descriptor -> oracle/graal#522

asm -> test if asm can be used to inspect class files

Both of them work, but they maybe can be tweaked to require less
manual configuration.
@dsyer
Copy link
Author

dsyer commented Apr 1, 2019

This app works for me with GraalVM rc14, as long as I have java.util.List in the reflection config JSON. I guess that's expected (and therefore this is fixed)? Sample app with full build config: https://github.com/sdeleuze/graal-issues/tree/master/property-descriptor.

sdeleuze pushed a commit to sdeleuze/graalvm-native-issues that referenced this issue Apr 1, 2019
property-descriptor -> oracle/graal#522

asm -> test if asm can be used to inspect class files

Both of them work, but they maybe can be tweaked to require less
manual configuration.
@cstancu
Copy link
Member

cstancu commented Apr 1, 2019

@dsyer yes, if adding java.util.List to the reflection config fixes the problem then I wouldn't consider this a bug. Thank you for reporting back!

@cstancu cstancu removed the bug label Apr 1, 2019
@cstancu cstancu closed this as completed Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants