Skip to content

Commit

Permalink
8284884: Replace polling with waiting in javax/swing/text/html/parser…
Browse files Browse the repository at this point in the history
…/Parser/8078268/bug8078268.java

Backport-of: 53580b336ac83addfaf20763e37781cebec7c531
  • Loading branch information
GoeLin committed Oct 11, 2022
1 parent 01d99fa commit a6fafe8
Showing 1 changed file with 19 additions and 17 deletions.
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,50 +24,52 @@

import java.io.File;
import java.io.FileReader;
import java.util.concurrent.CountDownLatch;

import javax.swing.SwingUtilities;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

/* @test
@bug 8078268
@summary javax.swing.text.html.parser.Parser parseScript incorrectly optimized
@author Mikhail Cherkasov
@run main bug8078268
*/
public class bug8078268 {
static volatile boolean parsingDone = false;
static volatile Exception exception;
private static final long TIMEOUT = 10_000;

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 {
long timeout = 10_000;
long s = System.currentTimeMillis();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
HTMLEditorKit htmlKit = new HTMLEditorKit();
Document doc = htmlKit.createDefaultDocument();
try {
htmlKit.read(new FileReader(getDirURL() + "slowparse.html"), doc, 0);
parsingDone = true;
htmlKit.read(new FileReader(getAbsolutePath()), doc, 0);
} catch (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) {
throw exception;
}
if (took > timeout) {
throw new RuntimeException("Parsing takes too long.");
}
}

static String getDirURL() {
return new File(System.getProperty("test.src", ".")).getAbsolutePath() +
File.separator;
private static String getAbsolutePath() {
return System.getProperty("test.src", ".")
+ File.separator + FILENAME;
}
}

1 comment on commit a6fafe8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.