Skip to content

Commit a70a7de

Browse files
tomballcopybara-github
authored andcommitted
Automated g4 rollback of changelist 638827797.
*** Reason for rollback *** Roll-forward: previous static reference to java.lang.reflect.GenericDeclaration in Java failed because it's an interface, and so was transpiled to an ObjC protocol. This CL makes a native static reference to the protocol's backing class. *** Original change description *** Automated g4 rollback of changelist 638722935. *** Reason for rollback *** com.google.gson.internal.reflect.ReflectionHelper$RecordSupportedHelper was unable to reflect on java.lang.reflect.GenericDeclaration. *** Original change description *** Supports linking the core jre_emul subset library without the `-ObjC` flag, by making static references to classes that are dynamically loaded. The static references ensure that the classes continue to be linked into the app. PiperOrigin-RevId: 639112548
1 parent 536df7d commit a70a7de

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

jre_emul/Classes/com/google/j2objc/util/logging/IOSLogHandler.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import java.io.PrintWriter;
1818
import java.io.StringWriter;
19-
import java.util.logging.Formatter;
2019
import java.util.logging.Handler;
20+
import java.util.logging.SimpleFormatter;
2121
import java.util.logging.LogRecord;
2222

2323
/*-[
@@ -92,14 +92,25 @@
9292
#pragma clang diagnostic pop
9393
]-*/
9494

95+
/*-[
96+
// Static, unused reference to java.lang.reflect.GenericDeclaration's backing interface.
97+
// Normally apps don't reflect on protocols, but this is necessary to support GSON,
98+
// which does.
99+
#include "java/lang/reflect/GenericDeclaration.h"
100+
__attribute__((unused)) void generic_declaration_class_reference(void) {
101+
static IOSClass *cls;
102+
cls = JavaLangReflectGenericDeclaration_class_();
103+
}
104+
]-*/
105+
95106
/**
96107
* Handler implementation that calls iOS asl_log(), or os_log() if supported by the OS.
97108
*
98109
* @author Tom Ball
99110
*/
100111
public class IOSLogHandler extends Handler {
101112

102-
static class IOSLogFormatter extends Formatter {
113+
static class IOSLogFormatter extends SimpleFormatter {
103114

104115
/**
105116
* Very simple formatter, since asl_log adds its own text.

jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/logging/LogManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ private void processParentHandlers(final Logger logger, final String name) {
883883
public Void run() {
884884
*/
885885
if (logger != owner.rootLogger) {
886-
boolean useParent = owner.getBooleanProperty(name + ".useParentHandlers", true);
886+
boolean useParent = owner.getBooleanProperty(name + ".useParentHandlers", true);
887887
if (!useParent) {
888888
logger.setUseParentHandlers(false);
889889
}
@@ -1935,4 +1935,7 @@ static void invokePropertyChange(Object listener, Object ev) {
19351935
}
19361936
}
19371937
}
1938+
1939+
// j2objc: ensure dynamically loaded class support class is linked.
1940+
private static final Class<?> unused = LoggingProxyImpl.class;
19381941
}

0 commit comments

Comments
 (0)