pubnub / java

PubNub Java-based APIs for core Java, Android
Other
672 stars 0 forks source link

Remove dependecy to jdk.unsupported #276

Open lreto opened 1 year ago

lreto commented 1 year ago

Most DTOs in the PubNub SDK don't have a default (empty) constructor. Gson, which is used to serialize and deserialize the DTOs, uses the empty constructor to create instances of the DTO classes. If this is not possible (as it is the case in most classes of the PubNub SDK), sun.misc.Unsafe.allocateInstance() is used for the allocation. This works fine under normal circumstances. However, since we use PubNub on a hardware with limited resources, we try to minimize the JRE size and memory usage. We use a tailored JRE that includes as few modules as possible. sun.misc.Unsafe.allocateInstance() is part of the jdk.unsupported module, which we normally don't include in our JRE.

It would be helpful for us if empty constructors were added to all DTOs (for example with Lombok's @NoArgsConstructor) so that the PubNub SDK worked without the jdk.unsupported module.

Swastik-Chakravorty commented 1 year ago

I want to contribute, to add empty constructors to DTOs. But please suggest me which DTO classes are where can I find those. This will be my first contribution if you kindly help.

lreto commented 1 year ago

The following classes caused troubles in our case:

Swastik-Chakravorty commented 1 year ago

Do you mean to do this only in all files?

public class SubscriptionItem {

private String name;
private Object state;    

public SubscriptionItem();

}

lreto commented 1 year ago

It would also be possible to do this with a Lombok annotation. This would look something like this

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SubscribeMessage {

@AllArgsConstructor is needed for the @Builder I think.

kleewho commented 1 year ago

Thank you all. We will look into it

r1shhh1 commented 9 months ago

Is this issue still open? I would like to work on this if it is.