Saturday, August 18, 2012

Safe Reformatting of Javadoc Hyperlinks

 I was gonna write, and did write, a little piece on Safe Reformatting of Javadoc Hyperlinks. Ironically, the blogger.com rendered the blog post wrong. I then clicked 'Go back to draft' or whatever it'd be called in English, because I thought I had published the thing. The saved version turned out to be blank after that. That sucked a bit.

I'll have to redo it then, and never mind the Javadoc examples that rendered wrong.

The trick is to use double quotes for your href hyperlink attribute value, not single quotes. The Eclipse Javadoc formatter will never break a doubly-quoted string, it seems. When I used single-quoted href values, the fomatter would often chop off characters from the link text one by one, and put on the next line, and also separate the "
"  would disintegrate too. With doubly quoted string, the '>' and link text will most probably end up on a new line, and be safe from chopping.
A second trick is to put spaces between the angles and the link text, e.g. '[...]> link-text
'. That will probably help with the above shredding too; the formatter will prefer to break on spaces, rather than between '<' and '/a>', which has happened to me a lot.
PS. Or somebody fix the Eclipse formatter... and while you're at it, add a better escape than @code and @literal, which don't work with '@' in the escaped text.

EDIT: Well look at that, the rendering is fuggled up again. Never mind. Here's another tip: never paste html into the blogger editor. And tip 2: edit your posts using not the blogger editor...

UPDATE: Just noticed that leaving a space before the link ('anchor') end tag makes the space be underlined; even if there is another space after the end tag. So leading space may be enough. Or no space at all, the double-quoting may be sufficient.

Wednesday, August 15, 2012

Eclipse Extract Method Not All Paths End In Return

Here's an almost interesting find. I had code like the following:
[statements]
if (...) {
  return;
}
[statements]
if (...) {
  return;
}
[statements, but not 'return;']
Did 'Extract Method' on the above section. Got an error for "Not All Paths End In Return", even though refactoring should work fine.

No big deal. Actually it makes sense, since refactoring means not to change meaning, and refactored meaning should probably be along this line:
refactoredMethod(...); return; 

And by that reasoning the error is good. But it so happened that in my attempted refactoring, the continuation of the refactored section had no more code, just getting out of the method, so the refactoring in my mind (no return in front) wouldn't have changed the meaning, if you follow me.

Anyhow. I just pushed the refactoring forward, overriding the error.


Monday, August 13, 2012

Stack Overflow - Me Subjective?

I was going to ask another question on the developer's go-to site #2 (Google search is number one, I believe) Stack Overflow. But before I finished the question, I get a 'subjective' warning/hint: 


Sort of funny-weird. Makes me wonder what kind of heuristic they employ for this. The wording so far actually contains nothing at all to go on. Well that's a reason to close the question of course, but subjective? Must be the hardest thing to make a computer decide if something is subjective. Maybe it's some statistical calculation: 'your' and 'own' could be common in asking for subjective opinion, like 'what are your own views on X?'.

And what makes it guess that this is likely to be a finished headline? Now of course, it can't, headlines don't even have to be sentences; and don't have to end with a question mark.

Maybe they do get a lot of subjective questions.

EDIT: Yep, 'your own' seems to trigger the subjectivity. Substituted 'our own'.

Tuesday, August 7, 2012

Jackson JsonMappingException: Infinite recursion

EDIT2: found a solution...see bottom.

EDIT: Ignore (some of) the stuff below :). Just occurred to me that it's not possible to check for circularity when a getter returns a new instance, and if that's the cause of the infinite recursion. And this seems to be the case for java.awt.Point's getLocation().

---- original text follows ----

What did the Jackson programmer/s do here?
org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->jav...
This doesn't help very much.

Wouldn't it be both easier and better feedback to detect circularity directly?

Could be implemented as a [[Identity]Hash]Set, where objects to be serialized are added on entering and removed again on exit (to allow sharing).

Or there might be reasons to use the StackOverflowError; but then the chain should be shown from the root, not from the top, since that would show the path to your problem. If length is a problem, the part just before the cycle is usually the most interesting. Do the hash set thing, and on first hit, you know you have detected the cycle. One might even show both the path leading up to the cycle, and the objects making up the cycle. Very valuable feedback; and almost trivial to implement, if one happens to have the time to do it.

For those of you happen to be coming here in need of a solution: use JsonIgnore, for instance. Like this:

@JsonIgnore
public BufferedImage javaBufferedImage;
If a BufferedImage happens to be the thing that has a java.awt.Point. Or consider a redesign where you don't mix non-serializable types in with serializable stuff.

BTW, the reason Point is not directly Jackson-serializable, is it's getLocation() (also has setLocation()) getter, I think.

EDIT2:

Found a somewhat general way to debug infinite recursion: configure Jackson to output an indented stream. Then check for a reasonable indentation depth, and cut the output at that point, since it's almost guaranteed to be caused by the infinite recursion. This should make it possible to manually inspect the output.

A consideration here is the fact that the Java debug protocol, the Eclipse debugger, and/or the Eclipse console seems fundamentally unable to efficiently handle large amounts of text or lines of text. So you might want to output the text to a file for viewing in your favorite editor. Or suffer.

I don't have the time right now to publish the source code I use; maybe later. Parting gift: a (partial!) java BufferedImage as JSON to admire:

      "bufferedImage" : {
        "type" : 6,
        "data" : {
          "pixelStride" : 4,
          "scanlineStride" : 420,
          "dataOffsets" : [ 3, 2, 1, 0 ],
          "dataStorage" : "/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf/ezMX/3szF/97Mxf
[...]


Sunday, July 8, 2012

Motivation

I really should write something about motivation. It's very important for any work to be done, and perhaps even more important, maybe even essential, in the field of software development; for reasons I would try to analyse in such a piece. This, however, is not it. You can guess why.

Tuesday, July 3, 2012

Chrome Multiuser Simple Tip For Developers

When testing a web application with multiple accounts, it can be pain in the neck to have to log in with the different accounts. Chrome's multiple users feature comes in handy here. ...That's all.

Sunday, July 1, 2012

Juno

Been trying out Eclipse Juno for a little while. I can't find any improvement at all in using it, compared to the previous version I use. Maybe I'll have to dig into some preference settings to activate that new spiffylicious Java Recommendation engine.

What seems to not have changed, in particular, is the Open Resource dialog, one I use three times a minute or something: still only prefix matching (you have to type the star yourself), still no reordering matching, and worst, no matching on folder names. These simple features would be worth a lot. 

I didn't import my old settings, so I had to manually set up some things; e.g. the menus. Why aren't the 
(new) Package, Class, Interface, Folder, shown by default? Easy enough to add, "Customize Perspective...", and "Menu" something. Checkboxes to check and uncheck. But why are these not part of the default in menus? 

And why do the group of 'Project' actions show at the top of the 'New' menu? It's almost ridiculous: 


Like that's the most common operations: 'we create new projects every three minutes, don't everybody?'. I sure don't. It's once a month or something. The class/folder/interface, OTOH. So uncheck all those project things, and you have: 

There.