Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change target Java version to 7 #2043

Merged
merged 3 commits into from Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -34,6 +34,25 @@ Maven:

![Build Status](https://github.com/google/gson/actions/workflows/build.yml/badge.svg)

### Requirements
#### Java version
- Gson 2.9.0 and newer: Java 7
- Gson 2.8.9 and older: Java 6

Despite supporting older Java versions, Gson also provides a JPMS module descriptor (module name `com.google.gson`) for users of Java 9 or newer.

#### JPMS dependencies (Java 9+)
These are the optional Java Platform Module System (JPMS) JDK modules which Gson depends on.
This only applies when running Java 9 or newer.

- `java.sql` (optional since Gson 2.8.9)
When this module is present, Gson provides default adapters for some SQL date and time classes.

- `jdk.unsupported`, respectively class `sun.misc.Unsafe` (optional)
When this module is present, Gson can use the `Unsafe` class to create instances of classes without no-args constructor.
However, care should be taken when relying on this. `Unsafe` is not available in all environments and its usage has some pitfalls,
see [`GsonBuilder.disableJdkUnsafe()`](https://javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/GsonBuilder.html#disableJdkUnsafe()).

### Documentation
* [API Javadoc](https://www.javadoc.io/doc/com.google.code.gson/gson): Documentation for the current release
* [User guide](https://github.com/google/gson/blob/master/UserGuide.md): This guide contains examples on how to use Gson in your code.
Expand Down
2 changes: 1 addition & 1 deletion codegen/README.md
@@ -1,4 +1,4 @@
# gson-codegen
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was an oversight by me; all other modules are using the folder name (instead of the artifact ID).

# codegen

This Maven module contains the source code for automatically generating Gson type adapters.

Expand Down
4 changes: 2 additions & 2 deletions gson/bnd.bnd
Expand Up @@ -3,8 +3,8 @@ Bundle-Name: ${project.name}
Bundle-Description: ${project.description}
Bundle-Vendor: Google Gson Project
Bundle-ContactAddress: ${project.parent.url}
Bundle-RequiredExecutionEnvironment: JavaSE-1.6, JavaSE-1.7, JavaSE-1.8
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7, JavaSE-1.8
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))"

# Optional dependency for JDK's sun.misc.Unsafe
# https://bnd.bndtools.org/chapters/920-faq.html#remove-unwanted-imports-
Expand Down
4 changes: 2 additions & 2 deletions gson/build.gradle
Expand Up @@ -4,8 +4,8 @@ apply plugin: 'maven'
group = 'com.google.code.gson'
version = '2.8.6-SNAPSHOT'

sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceCompatibility = 1.7
targetCompatibility = 1.7
Comment on lines -7 to +8
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably does not matter because the Gradle build is outdated anyway, see #1896.


sourceSets.main.java.exclude("**/module-info.java")
dependencies {
Expand Down
6 changes: 3 additions & 3 deletions gson/pom.xml
Expand Up @@ -58,8 +58,8 @@
<jdkToolchain>
<version>[1.5,9)</version>
</jdkToolchain>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -83,7 +83,7 @@
<configuration>
<excludePackageNames>com.google.gson.internal:com.google.gson.internal.bind</excludePackageNames>
<links>
<link>https://docs.oracle.com/javase/6/docs/api/</link>
<link>https://docs.oracle.com/javase/7/docs/api/</link>
</links>
</configuration>
</plugin>
Expand Down
5 changes: 3 additions & 2 deletions gson/src/main/java/com/google/gson/internal/$Gson$Types.java
Expand Up @@ -574,8 +574,9 @@ public Type getGenericComponentType() {

/**
* The WildcardType interface supports multiple upper bounds and multiple
* lower bounds. We only support what the Java 6 language needs - at most one
* bound. If a lower bound is set, the upper bound must be Object.class.
* lower bounds. We only support what the target Java version supports - at most one
* bound, see also https://bugs.openjdk.java.net/browse/JDK-8250660. If a lower bound
* is set, the upper bound must be Object.class.
*/
private static final class WildcardTypeImpl implements WildcardType, Serializable {
private final Type upperBound;
Expand Down
Expand Up @@ -30,15 +30,10 @@ public MalformedJsonException(String msg) {
}

public MalformedJsonException(String msg, Throwable throwable) {
super(msg);
// Using initCause() instead of calling super() because Java 1.5 didn't retrofit IOException
// with a constructor with Throwable. This was done in Java 1.6
initCause(throwable);
super(msg, throwable);
}

public MalformedJsonException(Throwable throwable) {
// Using initCause() instead of calling super() because Java 1.5 didn't retrofit IOException
// with a constructor with Throwable. This was done in Java 1.6
initCause(throwable);
super(throwable);
}
}
4 changes: 4 additions & 0 deletions gson/src/main/java/com/google/gson/stream/package-info.java
@@ -0,0 +1,4 @@
/**
* This package provides classes for processing JSON in an efficient streaming way.
*/
package com.google.gson.stream;
Expand Up @@ -161,7 +161,7 @@ public void testJavaSerialization() throws IOException, ClassNotFoundException {
}

@SafeVarargs
private <T> void assertIterationOrder(Iterable<T> actual, T... expected) {
private final <T> void assertIterationOrder(Iterable<T> actual, T... expected) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly when changing the version to Java 7 this caused a build failure (due to private methods not supporting @SafeVarargs in Java 7), but when the version was Java 6 this compiled fine. Most likely because @SafeVarargs was added in Java 7, but (unlike --release) the -source and -target compiler flags do not prevent using newer API.

ArrayList<T> actualList = new ArrayList<T>();
for (T t : actual) {
actualList.add(t);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -28,7 +28,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.6</java.version>
<java.version>1.7</java.version>
</properties>

<scm>
Expand Down