forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict the type of exception that can be thrown during target patte…
…rn parsing (and general target-oriented graph visitation) to QueryException. In practice, this is the only exception that can be thrown, but that fact is extremely non-obvious. We make it obvious by restricting the type of Exception that can be thrown to QueryExceptionMarkerInterface, an interface that is only non-trivially implemented by QueryException. PiperOrigin-RevId: 410355114
- Loading branch information
1 parent
6d50e69
commit be52530
Showing
30 changed files
with
267 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/google/devtools/build/lib/cmdline/QueryExceptionMarkerInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.cmdline; | ||
|
||
/** | ||
* Marker interface indicating either a {@link | ||
* com.google.devtools.build.lib.query2.engine.QueryException} or a {@link MarkerRuntimeException}. | ||
* Used with a generic type to indicate that a method can optionally throw {@code QueryException} if | ||
* the caller passes {@code QueryException.class} as a parameter to the method. | ||
* | ||
* <p>The only outside implementation of this interface is {@link | ||
* com.google.devtools.build.lib.query2.engine.QueryException}. Do not implement or extend! | ||
* | ||
* <p>Used to narrow a generic type like {@code E extends Exception} to {@code E extends Exception & | ||
* QueryExceptionMarkerInterface}, guaranteeing that the method will only throw {@link | ||
* com.google.devtools.build.lib.query2.engine.QueryException} if any exception of type E is thrown. | ||
* Because {@code E} will appear in the "throws" clause of a method, it must extend {@link | ||
* Exception}. | ||
*/ | ||
@SuppressWarnings("InterfaceWithOnlyStatics") | ||
public interface QueryExceptionMarkerInterface { | ||
/** | ||
* Marker class indicating that a given method does not throw QueryException. Pass {@code | ||
* MarkerRuntimeException.class} as a parameter. | ||
*/ | ||
class MarkerRuntimeException extends RuntimeException implements QueryExceptionMarkerInterface {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.