From e75517d561790bf8ee01763a1c75e091d03132e9 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Thu, 25 Jun 2020 23:01:06 +0200 Subject: Avoid class.getSimpleName except in static initializers or error messages --- src/utils/lombok/javac/JavacTreeMaker.java | 5 +---- src/utils/lombok/javac/java8/CommentCollectingTokenizer.java | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src/utils') diff --git a/src/utils/lombok/javac/JavacTreeMaker.java b/src/utils/lombok/javac/JavacTreeMaker.java index 20f4b66d..15a11151 100644 --- a/src/utils/lombok/javac/JavacTreeMaker.java +++ b/src/utils/lombok/javac/JavacTreeMaker.java @@ -343,10 +343,7 @@ public class JavacTreeMaker { Method method = getFromCache(m); try { if (m.returnType.isPrimitive()) { - Object res = method.invoke(owner, args); - String sn = res.getClass().getSimpleName().toLowerCase(); - if (!sn.startsWith(m.returnType.getSimpleName())) throw new ClassCastException(res.getClass() + " to " + m.returnType); - return (J) res; + return (J) method.invoke(owner, args); } return m.returnType.cast(method.invoke(owner, args)); } catch (InvocationTargetException e) { diff --git a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java index 08477e61..d7b1d569 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java +++ b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2019 The Project Lombok Authors. + * Copyright (C) 2013-2020 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 @@ -59,7 +59,7 @@ class CommentCollectingTokenizer extends JavaTokenizer { @Override public Token readToken() { Token token = super.readToken(); prevEndPosition = pos(); - if (textBlockStarts != null && (prevEndPosition - token.pos > 5) && token.getClass().getSimpleName().equals("StringToken")) { + if (textBlockStarts != null && (prevEndPosition - token.pos > 5) && token.getClass().getName().endsWith("$StringToken")) { char[] start = reader.getRawCharacters(token.pos, token.pos + 3); if (start[0] == '"' && start[1] == '"' && start[2] == '"') textBlockStarts.add(token.pos); } -- cgit