8284884: Replace polling with waiting in javax/swing/text/html/parser/Parser/8078268/bug8078268.java
Reviewed-by: serb, psadhukhan
This commit is contained in:
parent
bdf8a2a205
commit
53580b336a
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,50 +24,52 @@
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.text.Document;
|
import javax.swing.text.Document;
|
||||||
import javax.swing.text.html.HTMLEditorKit;
|
import javax.swing.text.html.HTMLEditorKit;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
@bug 8078268
|
@bug 8078268
|
||||||
@summary javax.swing.text.html.parser.Parser parseScript incorrectly optimized
|
@summary javax.swing.text.html.parser.Parser parseScript incorrectly optimized
|
||||||
@author Mikhail Cherkasov
|
|
||||||
@run main bug8078268
|
@run main bug8078268
|
||||||
*/
|
*/
|
||||||
public class bug8078268 {
|
public class bug8078268 {
|
||||||
static volatile boolean parsingDone = false;
|
private static final long TIMEOUT = 10_000;
|
||||||
static volatile Exception exception;
|
|
||||||
|
private static final String FILENAME = "slowparse.html";
|
||||||
|
|
||||||
|
private static final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
private static volatile Exception exception;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
long timeout = 10_000;
|
|
||||||
long s = System.currentTimeMillis();
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
HTMLEditorKit htmlKit = new HTMLEditorKit();
|
HTMLEditorKit htmlKit = new HTMLEditorKit();
|
||||||
Document doc = htmlKit.createDefaultDocument();
|
Document doc = htmlKit.createDefaultDocument();
|
||||||
try {
|
try {
|
||||||
htmlKit.read(new FileReader(getDirURL() + "slowparse.html"), doc, 0);
|
htmlKit.read(new FileReader(getAbsolutePath()), doc, 0);
|
||||||
parsingDone = true;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
}
|
}
|
||||||
|
latch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
while (!parsingDone && exception == null && System.currentTimeMillis() - s < timeout) {
|
|
||||||
Thread.sleep(200);
|
if (!latch.await(TIMEOUT, MILLISECONDS)) {
|
||||||
|
throw new RuntimeException("Parsing takes too long.");
|
||||||
}
|
}
|
||||||
final long took = System.currentTimeMillis() - s;
|
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
if (took > timeout) {
|
|
||||||
throw new RuntimeException("Parsing takes too long.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getDirURL() {
|
private static String getAbsolutePath() {
|
||||||
return new File(System.getProperty("test.src", ".")).getAbsolutePath() +
|
return System.getProperty("test.src", ".")
|
||||||
File.separator;
|
+ File.separator + FILENAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user