-1

Allright so after implementing the org.apache.commons.lang3.text.WordUtils class I was hoping to be able to use the WordUtils.wrap(String str, int width) function. But I reached a speed bump.

I was able to compile this program (which I should mention is an applet) without a single problem. I just had to set a CLASSPATH environment variable to reference the apache jar file, and then through appletviewer get the program to run. However when I reach the part of the code that uses the WordUtils.wrap() function everything turns sour and I get about 20 lines of runtime-errors on the command prompt.

Errors:

Caught a SecurityException reading the system property 'awt.toolkit'; the System
Utils property value will default to null.
Caught a SecurityException reading the system property 'file.encoding'; the Syst
emUtils property value will default to null.
Caught a SecurityException reading the system property 'java.awt.fonts'; the Sys
temUtils property value will default to null.
Caught a SecurityException reading the system property 'java.awt.graphicsenv'; t
he SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.awt.headless'; the
SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.awt.printerjob'; th
e SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.class.path'; the Sy
stemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.compiler'; the Syst
emUtils property value will default to null.
Caught a SecurityException reading the system property 'java.endorsed.dirs'; the
 SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.ext.dirs'; the Syst
emUtils property value will default to null.
Caught a SecurityException reading the system property 'java.home'; the SystemUt
ils property value will default to null.
Caught a SecurityException reading the system property 'java.io.tmpdir'; the Sys
temUtils property value will default to null.
Caught a SecurityException reading the system property 'java.library.path'; the
SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.runtime.name'; the
SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.runtime.version'; t
he SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.util.prefs.Preferen
cesFactory'; the SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.vm.info'; the Syste
mUtils property value will default to null.
Caught a SecurityException reading the system property 'user.country'; the Syste
mUtils property value will default to null.
Caught a SecurityException reading the system property 'user.region'; the System
Utils property value will default to null.
Caught a SecurityException reading the system property 'user.dir'; the SystemUti
ls property value will default to null.
Caught a SecurityException reading the system property 'user.home'; the SystemUt
ils property value will default to null.
Caught a SecurityException reading the system property 'user.language'; the Syst
emUtils property value will default to null.
Caught a SecurityException reading the system property 'user.name'; the SystemUt
ils property value will default to null.
Caught a SecurityException reading the system property 'user.timezone'; the Syst
emUtils property value will default to null.

Here is the line of code that causes all this trouble:

String strWrap = WordUtils.wrap("A really really really really really long sentence.", 50);

What's happening here?

Nigh7Sh4de
  • 395
  • 2
  • 7
  • 20
  • How about showing us a bit more code? Does your code use SystemUtils directly? SystemUtils is trying to read system properties that an applet is probably not allowed to read, due to the security restrictions in a browser. – DNA Sep 26 '12 at 22:34
  • No where in my code (which is a 200line file) do I use SystemUtils, just WordUtils...? – Nigh7Sh4de Sep 26 '12 at 22:35

2 Answers2

2

How about passing the line separator as an argument to bypass the SystemUtils access:

String strWrap = WordUtils.wrap("A really really really really really long sentence.", 50, "\n", false);
Guido Simone
  • 7,912
  • 2
  • 19
  • 21
  • Awesome that fixed my security issue! However no I have a different problem, isn't programming fun? :D... Ok, so I used your example and instead of putting in a newline, it put it nothing, literally nothing. Instead of: " A really really really really long sentence" I got: "A really reallyreally reallylong sentence"? – Nigh7Sh4de Sep 27 '12 at 00:56
  • Perhaps the control that is displaying your message expects CRLF. Try replacing "\n" with "\r\n". That's the disadvantage of not being able to use the system defined line separator. You have to guess. – Guido Simone Sep 27 '12 at 01:07
  • Allright so I did some digging (probobly should have that before all of this)... Turns out that my command: "Graphics.drawString()" cannot insert new lines or skip to the next line, it can only take a string and output the whole thing as a pixel image on ONE LINE. Thanks for all your help anyway :) – Nigh7Sh4de Sep 27 '12 at 01:29
1

Your code uses WordUtils which calls SystemUtils in order to find the line separator used by your system:

newLineStr = SystemUtils.LINE_SEPARATOR;

SystemUtils is trying to read system properties that an applet is probably not allowed to read, due to the security restrictions in a browser.

The documentation for SystemUtils says:

If a system property cannot be read due to security restrictions, the corresponding field in this class will be set to null and a message will be written to System.err

DNA
  • 42,007
  • 12
  • 107
  • 146
  • Allright so then what would I have to do to give my applet this permissions? – Nigh7Sh4de Sep 26 '12 at 22:42
  • You probably don't need to, since SystemUtils catches the errors and carries on regardless. Does the call to `WordUtils.wrap()` succeed? – DNA Sep 26 '12 at 22:45
  • Well unfortunately by "catching the errors" SystemUtils had also stopped the WordUtils.wrap() function froms executing bringing me back to square one, figuring out a way to wrap my text. So, what other line of code can I add? Or, if you know of a better way, how else could I wrap the text? – Nigh7Sh4de Sep 26 '12 at 22:47
  • Unless you also see an error message when SystemUtils tries to get the `line.separator` property (I don't see such an error in your listing above) then SystemUtils should not prevent WordUtils from working. How have you checked that `wrap()` is not working - is there an additional error you have not shown us? – DNA Sep 26 '12 at 22:54
  • I pasted the entire response that I recieved. I know that wrap() isn't working because if I comment it out and tell my applet to just draw some random string then it works perfectly fine. – Nigh7Sh4de Sep 27 '12 at 00:51