GavriYashar / Matlab-Editor-Plugin

Extends features for the matlab editor, Bookmarks, FileStructure, Clipboard stack
MIT License
74 stars 12 forks source link

Error when class contains custom property attributes #142

Closed Dev-iL closed 6 years ago

Dev-iL commented 6 years ago

This is a problem I encountered on R2018b.

Sometimes when working on a class that inherits from nnet.layer.Layer (that's how MATLAB wants us to make custom layers1 for neural networks) some Java error appears (see details below). From what I can gather, it's related to a custom properties attribute that is derived in the parent class. I'd expect MEP to ignore it gracefully.

Long stack trace ```none java.lang.IllegalArgumentException: No enum constant at.mep.editor.tree.EAttributes.LEARNABLE at java.lang.Enum.valueOf(Unknown Source) at at.mep.editor.tree.EAttributes.valueOf(EAttributes.java:10) at at.mep.editor.tree.MFile$Attributes$Attribute.getAttributeAsEAttribute(MFile.java:316) at at.mep.gui.fileStructure.NodeFS.setAttributes(NodeFS.java:103) at at.mep.gui.fileStructure.NodeFS.populateProperties(NodeFS.java:356) at at.mep.gui.fileStructure.NodeFS.constructForClassDef(NodeFS.java:306) at at.mep.editor.EditorWrapper.getNodeClass(EditorWrapper.java:747) at at.mep.editor.EditorWrapper.updateFieldsForActiveEditor(EditorWrapper.java:150) at at.mep.editor.EditorWrapper.getActiveEditorMTree(EditorWrapper.java:92) at at.mep.editor.EditorWrapper.getMTreeFast(EditorWrapper.java:773) at at.mep.editor.tree.MFile.construct(MFile.java:93) at at.mep.gui.fileStructure.NodeFS.constructForClassDef(NodeFS.java:283) at at.mep.gui.fileStructure.FileStructure.populate(FileStructure.java:325) at at.mep.gui.fileStructure.FileStructure.populateTree(FileStructure.java:350) at at.mep.editor.EditorApp.lambda$setCallbacks$0(EditorApp.java:220) at com.mathworks.mde.editor.MatlabEditor.fireEditorEvent(MatlabEditor.java:538) at com.mathworks.mde.editor.EditorViewClient$13.clientActivated(EditorViewClient.java:852) at com.mathworks.widgets.desk.DTClient.fireClientEvent(DTClient.java:1440) at com.mathworks.widgets.desk.DTClient.itemStateChanged(DTClient.java:1630) at com.mathworks.widgets.desk.DTInternalFrame.setSelected(DTInternalFrame.java:364) at com.mathworks.widgets.desk.DTClient.setSelected(DTClient.java:488) at com.mathworks.widgets.desk.DTOccupant.setSelected(DTOccupant.java:822) at com.mathworks.widgets.desk.DTDocumentContainer.setSelected(DTDocumentContainer.java:1070) at com.mathworks.widgets.desk.DTDocumentContainer.setSelected(DTDocumentContainer.java:1036) at com.mathworks.widgets.desk.DTGroup.setSelected(DTGroup.java:1077) at com.mathworks.widgets.desk.DTSelectionManager.eventDispatched(DTSelectionManager.java:396) at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Unknown Source) at java.awt.Toolkit.notifyAWTEventListeners(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) ```

1 No need to read the entire thing, just run this in the MATLAB command prompt:

edit(fullfile(matlabroot,'examples','nnet','main','preluLayer.m'))

and look at the first properties block.

GavriYashar commented 6 years ago

I'm sorry for the inconvenience. I'll fix it as soon as possible.

Dev-iL commented 6 years ago

@GavriYashar Are you sure that adding Learnable to the enum is a good idea? Learnable is merely an example of a a custom attribute that can appear in a MATLAB class (I say it's "custom" because it's not found in this list). I suspect there can be an endless amount of such attributes using the same mechanism (which is undocumented, as far as I can judge):

NewClass < ...
  nnet.layer.Layer < ...
    nnet.cnn.layer.mixin.Learnable < ...
      nnet.internal.cnnhost.LearnableAttributeClass

If the code of MEP has to be changed every time somebody (or TMW) adds a custom attribute to their class, I'd say this isn't good.

GavriYashar commented 6 years ago

It's not necessary to add them. These are only used in FileStructure to display certain icons next to properties and functions. Currently only a small amount of these enumerations are used. Maybe I'll use more in the future, maybe not.

It does no harm if it is not used. Also if there is no attribute in these enumerations it will return INVALID and just keeps working. As it already did, but without displaying any errors regarding some missing Attributes.