Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Add a little type safety to DaemonicParserState
Browse files Browse the repository at this point in the history
Summary: Otherwise it's too easy to obtain a cache for different type and get a runtime error (which I had during developement of another diff).

Reviewed By: styurin

shipit-source-id: d2a07b5bb7
  • Loading branch information
stepancheg authored and facebook-github-bot committed Aug 31, 2019
1 parent 3bffb05 commit 07bab57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/com/facebook/buck/parser/DaemonicParserState.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ LoadingCache<Cell, BuildFileTree> getBuildFileTrees() {
* types with generics. Care should be taken to ensure that the correct class object is passed in.
*/
@SuppressWarnings("unchecked")
public <T> PipelineNodeCache.Cache<BuildTarget, T> getOrCreateNodeCache(Class<?> cacheType) {
public <T> PipelineNodeCache.Cache<BuildTarget, T> getOrCreateNodeCache(Class<T> cacheType) {
try {
return (PipelineNodeCache.Cache<BuildTarget, T>) typedNodeCaches.get(cacheType);
} catch (ExecutionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.facebook.buck.core.cell.Cell;
import com.facebook.buck.core.config.BuckConfig;
import com.facebook.buck.core.model.BuildTarget;
import com.facebook.buck.core.model.impl.MultiPlatformTargetConfigurationTransformer;
import com.facebook.buck.core.model.targetgraph.TargetNode;
import com.facebook.buck.core.model.targetgraph.impl.TargetNodeFactory;
Expand Down Expand Up @@ -200,9 +201,14 @@ protected PerBuildState create(
MoreExecutors.listeningDecorator(
createExecutorService(rootCell.getBuckConfig(), "configured-pipeline"));

@SuppressWarnings("unchecked")
PipelineNodeCache.Cache<BuildTarget, TargetNode<?>> nodeCache =
daemonicParserState.getOrCreateNodeCache(
(Class<TargetNode<?>>) (Class<?>) TargetNode.class);

ParsePipeline<TargetNode<?>> targetNodeParsePipeline =
new RawTargetNodeToTargetNodeParsePipeline(
daemonicParserState.getOrCreateNodeCache(TargetNode.class),
nodeCache,
configuredPipelineExecutor,
rawTargetNodePipeline,
eventBus,
Expand Down

0 comments on commit 07bab57

Please sign in to comment.