Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: plugin might fail the server startup with IndexOutOfBoundsException #31

Closed
bellingard opened this issue May 11, 2016 · 12 comments
Closed
Assignees
Labels
Milestone

Comments

@bellingard
Copy link

We got this error while trying to install the latest 2.0.0 version of the plugin on Nemo. Root cause is:

Caused by: java.lang.IndexOutOfBoundsException: start index (-1) must not be negative
at com.google.common.base.Preconditions.checkPositionIndexes(Preconditions.java:389) ~[guava-17.0.jar:na]
at com.google.common.collect.ImmutableList.subList(ImmutableList.java:381) ~[guava-17.0.jar:na]
at com.google.common.collect.ImmutableList.subList(ImmutableList.java:61) ~[guava-17.0.jar:na]
at com.qualinsight.plugins.sonarqube.badges.font.FontManager.detectFontFamily(FontManager.java:109) ~[na:na]
at com.qualinsight.plugins.sonarqube.badges.font.FontManager.(FontManager.java:60) ~[na:na]

You can find the full log here: http://pastebin.com/8nUvbdAE

pawlakm added a commit that referenced this issue May 11, 2016
@pawlakm pawlakm added the bug label May 11, 2016
@pawlakm pawlakm self-assigned this May 11, 2016
@pawlakm pawlakm added this to the 2.0.1 milestone May 11, 2016
@pawlakm
Copy link
Member

pawlakm commented May 11, 2016

Hi Fabrice,

The problem occurs when none of the fonts specified as "preferred" in the plugin's code are available on the machine running SQ. It seems that none of "DejaVu Sans", "Verdana", "Tahoma", "Helvetica", "Arial", "sans-serif", is available on Nemo (which is quite odd as Helvetica is available on most Mac OS X / Linux boxes, and Arial is available on Windows ones).

As discussed per email, please compile this little program, execute it then send me back the file it produces: FontLister.java.gz It will allow me to improve font selection.

gunzip FontLister.java.gz
javac FontLister.java
java FontLister

For now, I fixed the NPE in f51f79c, but the width of produced SVG images is probably wrong if the plugin cannot use a font that is available.

Thanks and sorry for the inconvenience.

Michel

@mdiskin
Copy link

mdiskin commented May 12, 2016

I had the same error on our RHEL server (2.6.32-573.22.1.el6.x86_64)

Available fonts:
Century Schoolbook L Bold:Century Schoolbook L
Century Schoolbook L Bold Italic:Century Schoolbook L
Century Schoolbook L Italic:Century Schoolbook L
Century Schoolbook L Roman:Century Schoolbook L
Dialog.bold:Dialog
Dialog.bolditalic:Dialog
Dialog.italic:Dialog
Dialog.plain:Dialog
DialogInput.bold:DialogInput
DialogInput.bolditalic:DialogInput
DialogInput.italic:DialogInput
DialogInput.plain:DialogInput
Dingbats :Dingbats
Hershey Gothic- English:Hershey
Hershey Gothic- German:Hershey
Hershey Gothic- Italian:Hershey
Hershey Plain- Duplex:Hershey
Hershey Plain- Duplex- Italic:Hershey
Hershey Plain- Triplex:Hershey
Hershey Plain- Triplex- Italic:Hershey
Hershey Script- Complex:Hershey
Hershey Script- Simplex:Hershey
Lucida Bright Demibold:Lucida Bright
Lucida Bright Demibold Italic:Lucida Bright
Lucida Bright Italic:Lucida Bright
Lucida Bright Regular:Lucida Bright
Lucida Sans Demibold:Lucida Sans
Lucida Sans Regular:Lucida Sans
Lucida Sans Typewriter Bold:Lucida Sans Typewriter
Lucida Sans Typewriter Regular:Lucida Sans Typewriter
Monospaced.bold:Monospaced
Monospaced.bolditalic:Monospaced
Monospaced.italic:Monospaced
Monospaced.plain:Monospaced
Nimbus Mono L Bold:Nimbus Mono L
Nimbus Mono L Bold Oblique:Nimbus Mono L
Nimbus Mono L Regular:Nimbus Mono L
Nimbus Mono L Regular Oblique:Nimbus Mono L
Nimbus Roman No9 L Medium:Nimbus Roman No9 L
Nimbus Roman No9 L Medium Italic:Nimbus Roman No9 L
Nimbus Roman No9 L Regular:Nimbus Roman No9 L
Nimbus Roman No9 L Regular Italic:Nimbus Roman No9 L
Nimbus Sans L Bold:Nimbus Sans L
Nimbus Sans L Bold Condensed:Nimbus Sans L
Nimbus Sans L Bold Condensed Italic:Nimbus Sans L
Nimbus Sans L Bold Italic:Nimbus Sans L
Nimbus Sans L Regular:Nimbus Sans L
Nimbus Sans L Regular Condensed:Nimbus Sans L
Nimbus Sans L Regular Condensed Italic:Nimbus Sans L
Nimbus Sans L Regular Italic:Nimbus Sans L
SansSerif.bold:SansSerif
SansSerif.bolditalic:SansSerif
SansSerif.italic:SansSerif
SansSerif.plain:SansSerif
Serif.bold:Serif
Serif.bolditalic:Serif
Serif.italic:Serif
Serif.plain:Serif
Standard Symbols L:Standard Symbols L
URW Bookman L Demi Bold:URW Bookman L
URW Bookman L Demi Bold Italic:URW Bookman L
URW Bookman L Light:URW Bookman L
URW Bookman L Light Italic:URW Bookman L
URW Chancery L Medium Italic:URW Chancery L
URW Gothic L Book:URW Gothic L
URW Gothic L Book Oblique:URW Gothic L
URW Gothic L Demi:URW Gothic L
URW Gothic L Demi Oblique:URW Gothic L
URW Palladio L Bold:URW Palladio L
URW Palladio L Bold Italic:URW Palladio L
URW Palladio L Italic:URW Palladio L
URW Palladio L Roman:URW Palladio L
Utopia Bold:Utopia
Utopia Bold Italic:Utopia
Utopia Italic:Utopia
Utopia Regular:Utopia

@pawlakm
Copy link
Member

pawlakm commented May 12, 2016

Hi, thanks for your feedback. As it seems that the problem isn't isolated, I'll change the way the plugin generates SVG files in order to use CSS style sheets. This will remove the need to have fonts installed on the machine running SQ.

@bellingard
Copy link
Author

👍 :-)

pawlakm added a commit that referenced this issue May 12, 2016
@pawlakm
Copy link
Member

pawlakm commented May 12, 2016

I spent the whole evening trying to use CSS instead of fixed widths and my conclusions are the following:

  • I hate SVG generation,
  • CSS support in SVG is poor (at least what is supposed to be simple in HTML + CSS is overly complex in SVG)...
  • having cross browser compatibility is difficult

Unless someone has a brilliant idea in order to generate easily SVG with CSS, I won't spend more time on trying to fix this issue using CSS until SVG generation is made easier / until someone contributes a SVG image template that uses CSS I could use (instead of having to generate SVG images, I would then fill the template with data such as label text, value text, colors and background colors).

Until then, instead of using CSS, I fixed the issue as follows:

  • selected an alternative open source font (PT Sans) that looks nice and that is quite similar to Verdana
  • added the font to the plugin's GitHub repository along with its license
  • modified the plugin in order to load this font at SQ's startup
  • modified SVG generation in order to have the plugin embed the font directly in the generated image
  • made the plugin draw text as shape instead of text

The result is the following:

  • the image is generated correctly even if server does not have the font
  • the image is correctly displayed client side even if the client does not have the font
  • image width is correct

There are two shortcomings:

  • text rendering is unfortunately a bit uglier than with direct TTF usage due to font transformation to shape. Text is thiner and I could not find a way to increase the stroke's weight without having to use a bold font.
  • image weight is unfortunately ways higher than with previous version (almost x4.5 for a QG badge, x9 for some measure badges that display long text). This is due to text rendering as shapes.

I'll release the plugin with version 2.0.1-RC1, it would be great if you could try it and send me a feedback.

Thanks in advance,

Michel

pawlakm added a commit that referenced this issue May 13, 2016
@mdiskin
Copy link

mdiskin commented May 13, 2016

Sorry a little out of my depth; I hear good things on D3 if that's not something you came across in your travels.

I can try the RC tomorrow and report back.

Thanks

Sent with Good (www.good.com)


From: Michel Pawlak
Sent: Thursday, May 12, 2016 7:52:24 PM
To: QualInsight/qualinsight-plugins-sonarqube-badges
Cc: Mark Diskin; Manual
Subject: Re: [QualInsight/qualinsight-plugins-sonarqube-badges] Bug: plugin might fail the server startup with IndexOutOfBoundsException (#31)

I spent the whole evening trying to use CSS instead of fixed widths and my conclusions are the following:

  • I hate SVG generation,
  • CSS support in SVG is poor (at least what is supposed to be simple in HTML + CSS is overly complex in SVG)...
  • having cross browser compatibility is difficult

Unless someone has a brilliant idea in order to generate easily SVG with CSS, I won't spend more time on trying to fix this issue using CSS until SVG generation is made easier / until someone contributes a SVG image template that uses CSS I could use (instead of having to generate SVG images, I would then fill the template with data such as label text, value text, colors and background colors).

Until then, instead of using CSS, I fixed the issue as follows:

  • selected an alternative open source font (PT Sans) that looks nice and that is quite similar to Verdana
  • added the font to the plugin's GitHub repository along with its license
  • modified the plugin in order to load this font at SQ's startup
  • modified SVG generation in order to have the plugin embed the font directly in the generated image
  • made the plugin draw text as shape instead of text

The result is the following:

  • the image is generated correctly even if server does not have the font
  • the image is correctly displayed client side even if the client does not have the font
  • image width is correct

There are two shortcomings:

  • text rendering is unfortunately a bit uglier than with direct TTF usage due to font transformation to shape. Text is thiner and I could not find a way to increase the stroke's weight without having to use a bold font.
  • image weight is unfortunately ways higher than with previous version (almost x4.5 for a QG badge, x9 for some measure badges that display long text). This is due to text rendering as shapes.

I'll release the plugin with version 2.0.1-RC1, it would be great if you could try it and send me a feedback.

Thanks in advance,

Michel


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHubhttps://github.com//issues/31#issuecomment-218917900

pawlakm added a commit that referenced this issue May 13, 2016
@pawlakm
Copy link
Member

pawlakm commented May 13, 2016

@mdiskin unfortunately javascript / D3 is not an option here as for instance Javascript cannot be added as markdown / added to GitHub *.md files.

I finally decided to adopt another strategy based on Font properties.

  • if the preferred font is available on the SQ machine, then use it to compute SVG sizes
  • otherwise use the embedded font to compute sizes, then specify in font-family attributes only fonts that are smaller than this fallback font.
  • in both cases the font is not embedded in the resulting SVG (the result was really ugly)

Result:

  • correct sizes
  • small files (up to 3k instead of 30k)

Can you please test release 2.0.1-RC2 ? Thanks in advance !

Michel

@mdiskin
Copy link

mdiskin commented May 13, 2016

I cannot see the RC2 jar just source zip.

Did you look at shields.io they use SVG images for MD pages and maybe see how they did it.

@pawlakm
Copy link
Member

pawlakm commented May 13, 2016

@mdiskin
Copy link

mdiskin commented May 13, 2016

The server starts up with plugin installed and I'm able to render badges (see attached in IE11 zoomed to 400%)

passing

@pawlakm
Copy link
Member

pawlakm commented May 13, 2016

Ok, thanks, the image (label width) isn't perfect, but it's better. There is still room for improvement ^^'

I had a look at shields.io, it provides a standalone service that needs to be deployed along with (or needs to be accessible to) the service using it. This is a heavier solution (install shields.io server, or configure network to be able to call the service) than just having a plugin that does the job. At my company this approach wouldn't be accepted (they would not accept to have to install and maintain a "badges" server that requires npm, nor would accept to open ports.) I'll continue thus trying to improve the plugin.

Concerning the images that are generated by shields.io, they provide the templates they use. I saw that they used some smart tricks to lower the weight. Food for the brain ;-)

Side note: they are facing exactly the same issue I'm facing: they base their width computation on Verdana.ttf, and, if not found, they use Helvetica.ttf for width approximation. The problem is that they do not embed these fonts in their application as these are paid fonts (that's why I decided to use and embed an open source font in my plugin) and unlike what they argue, font width will always be an approximation, unless both server and client have verdana.ttf installed (which exclude all *nix users).

Cheers and thanks for your help.

pawlakm added a commit that referenced this issue May 13, 2016
@pawlakm
Copy link
Member

pawlakm commented May 14, 2016

FYI, I released version 2.0.1-RC3. It uses a template based approach similar to what shields.io is doing, instead of using Apache Batik for SVG image generation. As a result, the images are nicer (text positioning), the weight of generated images is < 1KB and the plugin weights 3 MB less.

As the reported bug is now fixed I close this issue. I'll proceed with a vote for release soon.

Again thanks for your help.

@pawlakm pawlakm closed this as completed May 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants