Useful new preference in DDE 8.5.2 for Java Agents

Having the proper Eclipse Java editor instead of the old style editor was introduced in 8.5.1, but there was one huge annoyance. When you edited a Java file, you had to save that, but then also remember to save the agent as well. Cue plenty of swearing and head scratching when your change wasn't showing up.

Well in 8.5.2 there is a new preference setting which allows the agent to be automatically saved when you save the Java file:

Just check the "Autosave Java design element on save of individual Java sources" box to make your Java coding a lot less annoying.

Java Lesson for the Day

I am not sure how this bug got through our first round of testing but I have some code which looks like this...

String source = "The BNL";
String pattern = "If I had $1000000";
System.out.println(source.replaceAll(source, pattern));

I was getting an error of "java.lang.IndexOutOfBoundsException: No group 1". The astute amongst you will notice that this will never work as $ is a heavily used regex character. So what to do, either I could manually escape the pattern string, but that gets us into a whole hellish world of backslashes. So instead enter a static method that I hadn't tried before... Matcher.quoteReplacement().

What it does is escape the pattern string for me before then being used in the replaceAll process. So my fixed code looks like this:

String source = "The BNL";
String pattern = "If I had $1000000";
System.out.println(source.replaceAll(source, Matcher.quoteReplacement(pattern)));

Not a big thing but it had me scratching my head for a while this afternoon, so thought I'd write it down for future reference.