Skip to content

Commit

Permalink
Annotate the constructor of ComparisonFailureWithFacts with `@UsedB…
Browse files Browse the repository at this point in the history
…yReflection`.

This makes it possible to write a config that instructs Proguard to keep that constructor if it keeps the class.

I'm hoping that I don't need to explicitly instruct it to keep the class, since the class name appears as a literal argument to `Class.forName`. (I could just tell it to keep it "just to be safe," but then maybe we'd see problems with users who don't actually use Truth but end up with it at runtime anyway because it's somewhere in the transitive deps and we asked Proguard to keep it.)

(The reason we're using reflection in the first place is to support running without JUnit 4 on the classpath. See #333.)

RELNOTES=n/a
PiperOrigin-RevId: 462826082
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jul 23, 2022
1 parent eb4be0a commit f149531
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
final class ComparisonFailureWithFacts extends PlatformComparisonFailure implements ErrorWithFacts {
private final ImmutableList<Fact> facts;

@UsedByReflection
ComparisonFailureWithFacts(
ImmutableList<String> messages,
ImmutableList<Fact> facts,
Expand Down
25 changes: 25 additions & 0 deletions core/src/main/java/com/google/common/truth/UsedByReflection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2013 Google, Inc.
*
* 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.common.truth;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;

import java.lang.annotation.Target;

@Target({METHOD, FIELD, CONSTRUCTOR})
@interface UsedByReflection {}

0 comments on commit f149531

Please sign in to comment.