From 17972d59fa7e2eec6b73ba5da8234f5fa7ac2536 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 17 Mar 2014 21:56:49 +0100 Subject: [#590][refactor] Fix for deadlock in WeakHashMap. Refactored all code that used a WeakHashMap to fake a field. --- .../lombok/javac/java6/CommentCollectingParser.java | 13 ++++++------- .../javac/java6/CommentCollectingParserFactory.java | 16 ++++++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'src/utils/lombok/javac/java6') diff --git a/src/utils/lombok/javac/java6/CommentCollectingParser.java b/src/utils/lombok/javac/java6/CommentCollectingParser.java index 30192b06..215bf5b6 100644 --- a/src/utils/lombok/javac/java6/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java6/CommentCollectingParser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,8 +21,7 @@ */ package lombok.javac.java6; -import java.util.Map; - +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.EndPosParser; @@ -33,20 +32,20 @@ import com.sun.tools.javac.util.List; class CommentCollectingParser extends EndPosParser { - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; private final Lexer lexer; - protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, Map> commentsMap) { + protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, ReferenceFieldAugment> commentsField) { super(fac, S, keepDocComments); lexer = S; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } @Override public JCCompilationUnit compilationUnit() { JCCompilationUnit result = super.compilationUnit(); if (lexer instanceof CommentCollectingScanner) { List comments = ((CommentCollectingScanner)lexer).getComments(); - commentsMap.put(result, comments); + commentsField.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java index b250b898..124a05f7 100644 --- a/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,8 +22,8 @@ package lombok.javac.java6; import java.lang.reflect.Field; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; @@ -34,32 +34,32 @@ import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; public class CommentCollectingParserFactory extends Parser.Factory { - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; static Context.Key key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, Map> commentsMap) { + protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment> commentsField) { super(context); - this.commentsMap = commentsMap; + this.commentsField = commentsField; } @Override public Parser newParser(Lexer S, boolean keepDocComments, boolean genEndPos) { - Object x = new CommentCollectingParser(this, S, true, commentsMap); + Object x = new CommentCollectingParser(this, S, true, commentsField); return (Parser) x; // CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either //javac6's EndPosParser which extends Parser, or javac7's EndPosParser which implements Parser. //Either way this will work out. } - public static void setInCompiler(JavaCompiler compiler, Context context, Map> commentsMap) { + public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment> commentsField) { context.put(CommentCollectingParserFactory.key(), (Parser.Factory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsMap)); + field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); } catch (Exception e) { throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e); } -- cgit