This discussion is archived
14 Replies Latest reply: Apr 25, 2011 5:19 AM by 854607 RSS

creating ps file

854607 Newbie
Currently Being Moderated
Hi,

We have an application which creates a postscript file through java using javax.print API.

We recently upgraded the application to java 1.6 and noticed the ps file contains NaN and Infinity values in it. If we use java 1.4 then there is no problem.

These values do not allow processing of ps file, so we are unable to print the files.

Could you please help me regarding why these Nan and Infinity values are getting generated?

Moreover these values dont get generated always but sometimes.
  • 1. Re: creating ps file
    800268 Expert
    Currently Being Moderated
    Most likely you're dividing something by (a number very close to) zero.
  • 2. Re: creating ps file
    854607 Newbie
    Currently Being Moderated
    We are not passing any null or zero value to it.
  • 3. Re: creating ps file
    gimbal2 Guru
    Currently Being Moderated
    You are probably trying to blame the Java 6 JDK for this situation. Don't. There is a bug in your code that just didn't happen to show up when using Java 1.4. If you don't actively search for this bug, you'll be stuck until you downgrade again.
  • 4. Re: creating ps file
    800268 Expert
    Currently Being Moderated
    851604 wrote:
    We are not passing any null or zero value to it.
    I didn't see you passed it in, I said you might be dividing by it somewhere and trying to print the result of that.
    public class TestDouble {
        public static void main(String[] args) {
            System.out.println(1.0 / 0.0);
            System.out.println(0.0 / 0.0);
        }
    }
    Running in 6u23 and 7ea gives:

    Infinity
    NaN

    I don't have Java 1.4 installed.
  • 5. Re: creating ps file
    803691 Newbie
    Currently Being Moderated
    I don't have Java 1.4 installed.
    I have.

    $ java -version
    java version "1.4.2_03"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
    Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

    $ java TestDouble
    Infinity
    NaN
  • 6. Re: creating ps file
    854607 Newbie
    Currently Being Moderated
    I completely checked my code and we are not dividing anything by 0.0.... If we would have been then it would have produced the same result in 1.4 as well.

    This infinity and NaN gets generated in ps file only sometimes, when load on application is more.

    We are building the jar file for this ps generation in 1.4 whereas the java path we are referring is 1.6. Do you think that this could be the cause for this Infinity tags in the ps file?
  • 7. Re: creating ps file
    Kayaman Guru
    Currently Being Moderated
    Well, code checks to see if there are Nan/Infs and in those cases print out all the input. See if you can make a test case out of it.
  • 8. Re: creating ps file
    YoungWinston Expert
    Currently Being Moderated
    851604 wrote:
    I completely checked my code and we are not dividing anything by 0.0.... If we would have been then it would have produced the same result in 1.4 as well.
    Not necessarily so. Has your input not changed in any way in all that time?
    This infinity and NaN gets generated in ps file only sometimes, when load on application is more.
    Which may or may not be significant, but something is generating them; and the only thing I can think of is that some result (either float or double, or an equivalent wrapper class) is getting that value.
    You might want to re-check Walter's post, because it's possible that the result could be produced by division by a denormalized value close to, but not actually, 0 (my IEEE-754 knowledge doesn't extend that far).
    We are building the jar file for this ps generation in 1.4 whereas the java path we are referring is 1.6. Do you think that this could be the cause for this Infinity tags in the ps file?
    Maybe, but that's beyond my ken. maybe others will have an opinion.

    Winston
  • 9. Re: creating ps file
    EJP Guru
    Currently Being Moderated
    I think we're on the wrong track here. PS won't care about the text embedded in the stream, just about the PS instructions and data. If the PS contains NaNs such that it can't be printed they must be embedded values in the PS instructions, presumably (x,y) coordinates or lengths relative to the page being printed.
  • 10. Re: creating ps file
    800268 Expert
    Currently Being Moderated
    851604 wrote:
    This infinity and NaN gets generated in ps file only sometimes, when load on application is more.
    Sounds like a threading issue then. Using shared Date/NumberFormats or other objects which aren't thread safe?
  • 11. Re: creating ps file
    YoungWinston Expert
    Currently Being Moderated
    EJP wrote:
    I think we're on the wrong track here. PS won't care about the text embedded in the stream, just about the PS instructions and data. If the PS contains NaNs such that it can't be printed they must be embedded values in the PS instructions, presumably (x,y) coordinates or lengths relative to the page being printed.
    Totally agree, and I wasn't referring to embedded text; simply to the fact that "infinity" and "NaN" (and I notice that OP spelled them correctly) are likely evidence that something is being produced with those values.
    OP's perception is also that this has changed between 1.4 and 1.6, and I guess I was trying to work out if anything else has changed in that time (the lib producing the PS being just such a possibility).

    Winston
  • 12. Re: creating ps file
    854607 Newbie
    Currently Being Moderated
    After some more analysis, I came to this conclusion :

    If i remove all the Graphics.setFont lines from code, then there is no error!!

    Could you please guide me what could be the problem in this method??
  • 13. Re: creating ps file
    YoungWinston Expert
    Currently Being Moderated
    851604 wrote:
    If i remove all the Graphics.setFont lines from code, then there is no error!!
    Cool.
    Could you please guide me what could be the problem in this method??
    If this is java.awt.Graphics, then it's been around for a very long time, and I'm not aware of any changes that might cause what you're seeing (but I am a self-confessed duffer about GUI stuff).
    You could direct this question to the AWT/Swing threads under "Java Desktop" (but don't forget to indicate your crosspost). I'm afraid, however, I've never tried what you're doing; my observations were simply based on what you posted.

    Good luck.

    Winston
  • 14. Re: creating ps file
    854607 Newbie
    Currently Being Moderated
    Yes this one is related to java.awt.Graphics

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points