Skip to content

8353757: Log class should have a proper clear() method #24460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, 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 Down Expand Up @@ -267,7 +267,7 @@ void clear() {

if (ht.get(Log.logKey) instanceof ReusableLog) {
//log already inited - not first round
((ReusableLog)Log.instance(this)).clear();
Log.instance(this).clear();
Enter.instance(this).newRound();
((ReusableJavaCompiler)ReusableJavaCompiler.instance(this)).clear();
Types.instance(this).newRound();
Expand Down Expand Up @@ -395,11 +395,9 @@ static class ReusableLog extends Log {
this.context = context;
}

void clear() {
recorded.clear();
sourceMap.clear();
nerrors = 0;
nwarnings = 0;
@Override
public void clear() {
super.clear();
//Set a fake listener that will lazily lookup the context for the 'real' listener. Since
//this field is never updated when a new task is created, we cannot simply reset the field
//or keep old value. This is a hack to workaround the limitations in the current infrastructure.
Expand Down
14 changes: 14 additions & 0 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,20 @@ public void report(JCDiagnostic diagnostic) {
diagnosticHandler.report(diagnostic);
}

/**
* Reset the state of this instance.
*/
public void clear() {
recorded.clear();
sourceMap.clear();
nerrors = 0;
nwarnings = 0;
nsuppressederrors = 0;
nsuppressedwarns = 0;
while (diagnosticHandler.prev != null)
popDiagnosticHandler(diagnosticHandler);
}

/**
* Common diagnostic handling.
* The diagnostic is counted, and depending on the options and how many diagnostics have been
Expand Down