Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions jme3-core/src/main/java/com/jme3/util/PreserveReflection.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface PreserveReflection {
/**
* When true, metadata generators should also allow this type to be allocated
* without invoking a constructor.
*
* @return true to include unsafe allocation metadata
*/
boolean allowUnsafeAllocation() default true;
}
35 changes: 34 additions & 1 deletion jme3-nativeimage-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ public class MyNiftyController {
```

Classes annotated with `@PreserveReflection` are included by default when this
plugin generates metadata.
plugin generates metadata. They are also marked as unsafe-allocatable by default.
Disable that when a reflected type must always be constructed normally:

```java
@PreserveReflection(allowUnsafeAllocation = false)
public class ConstructorOnlyEntryPoint {
}
```


## Default Resource Settings
Expand Down Expand Up @@ -134,6 +141,32 @@ jmeNativeImage {
}
```

### Unsafe Allocation

The plugin automatically detects direct construction of known unsafe allocation
container types, such as `SafeArrayList(SomeType.class)`, in compiled classes and
adds unsafe allocation metadata for the corresponding `SomeType[]` array storage.
By default, the container list contains `com.jme3.util.SafeArrayList`.

You can also add explicit unsafe allocation entries:

```groovy
jmeNativeImage {
unsafeAllocatedType 'org.example.Foo'
unsafeAllocatedType 'org.example.Bar[]'
unsafeAllocatedType '[Lorg.example.Baz;'
}
```

If a project has another container type with the same `Class`-first constructor
pattern, add it to the detector:

```groovy
jmeNativeImage {
unsafeAllocationContainerType 'org.example.MyArrayStore'
}
```

### Proxy Interfaces

If your application uses dynamic proxies, configure the interface set:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class JmeNativeImageExtension {
final ListProperty<String> additionalTargetTypes
final ListProperty<String> additionalTargetAnnotations
final ListProperty<List<String>> additionalProxyInterfaceSets
final ListProperty<String> additionalUnsafeAllocatedTypes
final ListProperty<String> additionalUnsafeAllocationContainerTypes
final ListProperty<String> additionalResourceGlobs
final Property<String> includeResourcesPattern
final Property<String> excludeResourcesPattern
Expand All @@ -24,6 +26,8 @@ class JmeNativeImageExtension {
additionalTargetTypes = objects.listProperty(String).convention([])
additionalTargetAnnotations = objects.listProperty(String).convention([])
additionalProxyInterfaceSets = objects.listProperty(List).convention([])
additionalUnsafeAllocatedTypes = objects.listProperty(String).convention([])
additionalUnsafeAllocationContainerTypes = objects.listProperty(String).convention([])
additionalResourceGlobs = objects.listProperty(String).convention([])
includeResourcesPattern = objects.property(String)
excludeResourcesPattern = objects.property(String)
Expand All @@ -42,6 +46,14 @@ class JmeNativeImageExtension {
additionalProxyInterfaceSets.add(interfaceClassNames.toList())
}

void unsafeAllocatedType(String className) {
additionalUnsafeAllocatedTypes.add(className)
}

void unsafeAllocationContainerType(String className) {
additionalUnsafeAllocationContainerTypes.add(className)
}

void resourceGlob(String glob) {
additionalResourceGlobs.add(glob)
}
Expand Down
Loading