Problem with Frames in Java 8

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Raileth
Cave Troll
Posts: 28
Joined: Fri Oct 12, 2012 5:09 pm
Location: Camberley, UK

Problem with Frames in Java 8

Post by Raileth »

Hi,

I'm in the process of upgrading my framework from B90 to B91 so it can use java8 and have run into a problem with the character sheet macro that I have written. It seems to be linked to the use of frames and most of the time when I run it I get the following error:-
Spoiler
java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextNode(Unknown Source)
at java.util.LinkedHashMap$LinkedKeyIterator.next(Unknown Source)
at java.util.Collections$3.nextElement(Unknown Source)
at net.rptools.maptool.client.ui.htmlframe.HTMLPane.setText(HTMLPane.java:165)
at net.rptools.maptool.client.ui.htmlframe.HTMLPanel$2.run(HTMLPanel.java:92)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(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$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:36)
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)
The code for the frame is as follows:-
Spoiler
[frame("CharSheet"): {
[h: page = getStrProp(macro.args, "Page")]
[h,if(page==""): page="Main"]
<html>
<head>
<title>Character Sheet</title>
<link rel="stylesheet" type="text/css" href="CharSheet_css@[r: getMacroLocation()]">
</head>
<body>
[macro("CharSheetHeader@this"): page]
<br>
[macro("CharSheet"+page+"@this"): ""]
</body>
</html>
}]
Ive checked the rest of the code and it seems to run ok, but when I link it to the frame I get the error 9/10 times.

Any help gratefully received.

If you need a full copy of the framework you can download it here:-

https://dl.dropboxusercontent.com/u/169 ... lank.cmpgn

Thanks very much for any help

Grant
Raileth

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with Frames in Java 8

Post by aliasmask »

ConcurrentModificationException sounds like a race condition where you're trying to update something that is already being updated. Perhaps you're updating the frame on one line and then another process tries to update it again while it's still being loading? You should set up your error logs to include macro execution and then take a look at what's going on and when it happens.

username
Dragon
Posts: 277
Joined: Sun Sep 04, 2011 7:01 am

Re: Problem with Frames in Java 8

Post by username »

Doesn't look like a race condition. Usually such things happen when you modify a list you are iterating. Unless you choose the right iterator, that fails exactly like that. At the code in question (trunk) we have:

Code: Select all

StyleSheet style = document.getStyleSheet();
HTMLEditorKit.Parser parse = editorKit.getParser();
super.setText("");
Enumeration<?> snames = style.getStyleNames();
while (snames.hasMoreElements()) {
   style.removeStyle(snames.nextElement().toString());
}
This looks exactly like what I said. The styles enumaration (snames) is likely not a copy, but a reference into style. By doing style.remove that crashes. Intended is to empty the style sheet, which must be accomplished differently. The only workaround (w/o java code fix) I can think of is to drop the stylesheet reference in the macrocode. I assume the code otherwise works, so that the default style list is empty, which avoids the problem.

Raileth
Cave Troll
Posts: 28
Joined: Fri Oct 12, 2012 5:09 pm
Location: Camberley, UK

Re: Problem with Frames in Java 8

Post by Raileth »

I've removed the reference to the stylesheets in the macro, as suggested by username and it now works - although the frame isn't as pretty now :).

I have to be honest I'm not a java expert so the rest of the post was a bit alien to me :)

Is this therefore a bug that needs to be raised for version B91 - and if so how do I log it?

Thanks

Grant
Raileth

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with Frames in Java 8

Post by aliasmask »

Instead of doing this:

Code: Select all

<link rel="stylesheet" type="text/css" href="CharSheet_css@[r: getMacroLocation()]">
Try this:

Code: Select all

[H: styleSheet = getMacroCommand(getMacroIndexes("CharSheet_css","",getMacroLocation()),getMacroLocation())]
[R: strformat("style { %{styleSheet} }")]
 
Oh, you know what. I seem to recall running in to a problem using title. Maybe it's only a problem when using a style sheet. Try removing that line and using "Character Sheet" for the frame name. The code above should also work for the style sheet by just dumping the style text straight to the form.

I haven't tested this. If there is an error, it may be related to quotes in your style sheet. I would change strformat("...") to strformat('...') and see if that works.

username
Dragon
Posts: 277
Joined: Sun Sep 04, 2011 7:01 am

Re: Problem with Frames in Java 8

Post by username »

Raileth wrote: Is this therefore a bug that needs to be raised for version B91 - and if so how do I log it?
It is a bug (and relatively easy to fix) but I don't know how to log it, so that the powers that be fix it. Maybe they stumble across this. If aliasmask's suggestions work, use those. 1.3 development is coming to a close and I don't see many releases after b91.

Raileth
Cave Troll
Posts: 28
Joined: Fri Oct 12, 2012 5:09 pm
Location: Camberley, UK

Re: Problem with Frames in Java 8

Post by Raileth »

I have tried Aliasmasks code but to no avail - all I get is a macro execution error.
Removing the title from the html code has no effect, and changing the " to ' doenst work for the code either.

Thanks for the suggestions though

Grant
Raileth

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with Frames in Java 8

Post by aliasmask »

Confirmed. I just tested my Spell Library macro and I get the same error which worked fine in B89. Once a frame is created for the first time when MT is open no style sheet or style tag can be used without getting that error. Funny thing is, you can open the frame once with a style sheet. I guess there is sort of a workaround albeit a bad one. You can close the existing frame and open a newly named frame, but then you'll have to reposition and that would really make it not worth having a frame.

edit: I just tested something and it seemed to work. So, I'll have to see what the difference is. Btw, my code above was a bit off, but after correcting it, it still gave me that error.

My test code:

Code: Select all

[frame("Spell Library"): {<html><head><style>[r: "div {color:blue}"]</style></head><body><div>test</div></body></html>}]

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with Frames in Java 8

Post by aliasmask »

Okay, I think I figured it out. If there are 8 or more styles then I get the error. Having 7 is okay...

I'll do some more testing to see if it's related to the MT version or java.

edit: OMFG Oracle. This seems to be a java 8 related bug. If you uninstall java 8 and use java 7, your style sheets should work again. I don't know if there is an MT fix possible or if/when it would be applied.

username
Dragon
Posts: 277
Joined: Sun Sep 04, 2011 7:01 am

Re: Problem with Frames in Java 8

Post by username »

Well, this IS a bug in Maptool, Java 7 apparently has some internal different workings that prevent the bug from showing up. Maybe only with 100+ styles, who knows. Not using stylesheets but inlining styles (as you suggest) is a proper workaround.

(The same "Not-Oracle's-fault" was true for the ubiquitous Camparison exception; but there the bug was much harder to see.)

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with Frames in Java 8

Post by aliasmask »

Well, that's sort of good news. If it's an MT issue then there is something we can do about it. So, when's the next patch :D

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: Problem with Frames in Java 8

Post by Craig »

Does any one have a really simple example where this fails?
I tried the example campaign in the above post but I cant get it to fail (I suspect this is more with me not knowing what to set up and which buttons to push to reproduce it). If some one has a really simple example it will help greatly.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with Frames in Java 8

Post by aliasmask »

You download the 3.5/pathfinder framework and run the character sheet macro or the Spell Library macro at the bottom. It should open the first time okay, but if the frame is refreshed, then it errors. I would use the Spell Library macro because it has no token requirements.

username
Dragon
Posts: 277
Joined: Sun Sep 04, 2011 7:01 am

Re: Problem with Frames in Java 8

Post by username »

I have been trying for over an hour to get my eclipse to import the new GIT repo for 1.3 but couldn't get it to work. Probably I need a gradle plugin or similar. So here's the patch.
Around net.rptools.maptool.client.ui.htmlframe.HTMLPane.setText(HTMLPane.java:165) replace

Code: Select all

  Enumeration<?> snames = style.getStyleNames();
  while (snames.hasMoreElements()) {
    style.removeStyle(snames.nextElement().toString());
  }
with

Code: Select all

  List<?> snames = Collections.list(style.getStyleNames());
  for (Object name : snames) {
    style.removeStyle(name.toString());
  }
On the subject see also http://stackoverflow.com/questions/1088 ... s-iterator. (I also can't test this in real code.)

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: Problem with Frames in Java 8

Post by Craig »

username wrote:I have been trying for over an hour to get my eclipse to import the new GIT repo for 1.3 but couldn't get it to work. Probably I need a gradle plugin or similar. So here's the patch.
I assume you mean the 1.4 Git repository?

Which bit are you having trouble with the import from Git or the Gradle part?
I don't use Eclipse (I really dislike it a lot, it makes everything so complicated and screws up so often I spend more time getting it working again than coding).

Here is the setup tutorial for github and egit http://wiki.eclipse.org/EGit/User_Guide#GitHub_Tutorial
(It may actually just be easier to install the github client and use that for the initial clone, just reading through this makes me roll my eyes at how unnecessarily complicated things in eclipse are).

Here is the information for the Eclipse Gradle support
https://github.com/spring-projects/ecli ... ion-gradle

Post Reply

Return to “Macros”