defano / wyldcard

A clone of Apple's HyperCard and HyperTalk scripting language.
https://github.com/defano/wyldcard/wiki
MIT License
117 stars 12 forks source link

Exception when copying a field, something to do with protected field not made accessible ( #126

Open Jimw338 opened 1 year ago

Jimw338 commented 1 year ago

I'm getting an error when I try to paste a field that I just created and copied, somehow relating to improper permissions in the DefaultStyledDocument part of the FieldModel object, in member "sharedText/unsharedText" which are of type "Map<Integer, StyledDocument>". The exception occurs in the call to "Serializer.copy()" in CardPartTransferHandler:duplicatePart: PartModel copiedPartModel = Serializer.copy(original.getPartModel());"

and the exception trace print is below.

I had thought that this was some subtle bug introduced by my numerous modifications (I'm slowly working all of my original changes back into a copy of the current codebase, which looks like it's been refactored a bunch in places since I last worked on it 4 years ago. But I just noticed that this "field copy bug" happened even with source that I just downloaded, so it's not that.

How do you debug an error that originates from deep in the bowels of the API code itself?

Jim

com.defano.wyldcard.part.clipboard.CardPartTransferHandler: importData duplicatePart original = com.defano.wyldcard.part.field.FieldPart@4a202f04. original.getPartModel = com.defano.wyldcard.part.field.FieldModel@28c6bbe2. ..importData (EXCEPTION = {}) java.lang.reflect.InaccessibleObjectException: Unable to make field protected javax.swing.text.DefaultStyledDocument$ElementBuffer javax.swing.text.DefaultStyledDocument.buffer accessible: module java.desktop does not "opens javax.swing.text" to unnamed module @6ced7109 at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:387) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:363) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:311) at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:180) at java.base/java.lang.reflect.Field.setAccessible(Field.java:174) at com.google.gson.internal.reflect.UnsafeReflectionAccessor.makeAccessible(UnsafeReflectionAccessor.java:44) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:159) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102) at com.google.gson.Gson.getAdapter(Gson.java:489) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:56) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) at com.defano.wyldcard.serializer.PostConstructAdapterFactory$PostConstructAdapter.write(PostConstructAdapterFactory.java:79) at com.google.gson.Gson.toJson(Gson.java:735) at com.google.gson.Gson.toJson(Gson.java:714) at com.google.gson.Gson.toJson(Gson.java:669) at com.google.gson.Gson.toJson(Gson.java:649)


    at com.defano.wyldcard.serializer.Serializer.serialize(Serializer.java:46)
    at com.defano.wyldcard.serializer.Serializer.copy(Serializer.java:36)
    at com.defano.wyldcard.part.clipboard.CardPartTransferHandler.duplicatePart(CardPartTransferHandler.java:95)
    at com.defano.wyldcard.part.clipboard.CardPartTransferHandler.importData(CardPartTransferHandler.java:62)
    at java.desktop/javax.swing.TransferHandler$TransferAction.actionPerformedImpl(TransferHandler.java:1766)
    at java.desktop/javax.swing.TransferHandler$TransferAction$1.run(TransferHandler.java:1712)
    at java.desktop/javax.swing.TransferHandler$TransferAction$1.run(TransferHandler.java:1710)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
    at java.desktop/javax.swing.TransferHandler$TransferAction$2.run(TransferHandler.java:1730)
    at java.desktop/javax.swing.TransferHandler$TransferAction$2.run(TransferHandler.java:1728)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.desktop/javax.swing.TransferHandler$TransferAction.actionPerformed(TransferHandler.java:1727)
    at com.defano.wyldcard.part.clipboard.CardActionListener.actionPerformed(CardActionListener.java:20)
    at com.defano.wyldcard.menu.dispatcher.MenuMessageHandler.lambda$handleMessage$0(MenuMessageHandler.java:39)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:308)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Jimw338 commented 1 year ago

Okay, it has something to do with the "FieldModelObserver observer" and "Range selection" which Gson doesn't seem to like.

I found this page: https://stackoverflow.com/questions/4802887/gson-how-to-exclude-specific-fields-from-serialization-without-annotations

about how to exclude fields.. But they all look terribly complicated.

The "transient" keyword I gather is supposed to exclude the fields from serialization, but doesn't seem to work Something Oracle changed in the latest Java ? I have Java 19.0.1 2022-10-18 and SE Runtime Environment build 19.0.1+10-21.