11/*
2- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2424 * @test
2525 * @bug 8023213
2626 * @summary Font/Text APIs should not crash/takes long time
27- * if transform includes INIFINITY
27+ * if transform includes INFINITY
2828 * @run main DrawStringWithInfiniteXform
2929 */
30- import java .awt .* ;
31- import java .awt .font .* ;
32- import java .awt .geom .* ;
33- import java .awt .image .* ;
30+ import java .awt .Font ;
31+ import java .awt .Graphics2D ;
32+ import java .awt .geom .AffineTransform ;
33+ import java .awt .image .BufferedImage ;
3434import java .util .Timer ;
3535import java .util .TimerTask ;
3636
@@ -41,15 +41,22 @@ public class DrawStringWithInfiniteXform {
4141
4242 class ScheduleTask extends TimerTask {
4343 public void run () {
44- if (!done ) {
45- throw new
46- RuntimeException ("drawString with InfiniteXform transform takes long time" );
44+ System .out .println ("Task running at " + System .currentTimeMillis ());
45+ System .out .flush ();
46+ synchronized (DrawStringWithInfiniteXform .class ) {
47+ System .out .println (
48+ "Checking done at " + System .currentTimeMillis ());
49+ System .out .flush ();
50+ if (!done ) {
51+ throw new RuntimeException (
52+ "drawString with InfiniteXform transform takes long time" );
53+ }
4754 }
4855 }
4956 }
5057 public DrawStringWithInfiniteXform () {
5158 timer = new Timer ();
52- timer .schedule (new ScheduleTask (), 20000 );
59+ timer .schedule (new ScheduleTask (), 30000 );
5360 }
5461
5562 public static void main (String [] args ) {
@@ -58,11 +65,15 @@ public static void main(String [] args) {
5865 }
5966
6067 private void start () {
68+ System .out .println ("start at " + System .currentTimeMillis ());
69+ System .out .flush ();
6170 float [] vals = new float [6 ];
62- for (int i =0 ;i <6 ;i ++) vals [i ]=Float .POSITIVE_INFINITY ;
71+ for (int i =0 ; i <6 ; i ++) {
72+ vals [i ] = Float .POSITIVE_INFINITY ;
73+ }
6374 AffineTransform nanTX = new AffineTransform (vals );
6475
65- BufferedImage bi = new BufferedImage (1 ,1 , BufferedImage .TYPE_INT_RGB );
76+ BufferedImage bi = new BufferedImage (1 , 1 , BufferedImage .TYPE_INT_RGB );
6677 Graphics2D g2d = bi .createGraphics ();
6778
6879 g2d .rotate (Float .POSITIVE_INFINITY );
@@ -73,8 +84,12 @@ private void start() {
7384 g2d .setFont (xfiniteFont );
7485 g2d .drawString ("abc" , 20 , 20 );
7586 }
76- done = true ;
77- timer .cancel ();
87+ System .out .println ("Loop done at " + System .currentTimeMillis ());
88+ System .out .flush ();
89+ synchronized (DrawStringWithInfiniteXform .class ) {
90+ done = true ;
91+ timer .cancel ();
92+ }
7893 System .out .println ("Test passed" );
7994 }
8095}
0 commit comments