juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject [1/2] incubator-juneau git commit: Fix possible NPEs in Calendar and Date swaps.
Date Wed, 14 Jun 2017 19:01:19 GMT
Repository: incubator-juneau
Updated Branches:
  refs/heads/master d5ba83970 -> 9d086440e


Fix possible NPEs in Calendar and Date swaps.

Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/9475ed21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/9475ed21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/9475ed21

Branch: refs/heads/master
Commit: 9475ed212e035be5e6eeb681b000cfbd98f83bc1
Parents: d5ba839
Author: JamesBognar <jamesbognar@apache.org>
Authored: Wed Jun 14 14:56:53 2017 -0400
Committer: JamesBognar <jamesbognar@apache.org>
Committed: Wed Jun 14 15:00:33 2017 -0400

----------------------------------------------------------------------
 .../java/org/apache/juneau/transforms/CalendarSwap.java   | 10 ++++++++++
 .../java/org/apache/juneau/transforms/DateLongSwap.java   |  2 ++
 .../java/org/apache/juneau/transforms/DateMapSwap.java    |  2 ++
 .../main/java/org/apache/juneau/transforms/DateSwap.java  | 10 ++++++++++
 4 files changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9475ed21/juneau-core/src/main/java/org/apache/juneau/transforms/CalendarSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/CalendarSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/CalendarSwap.java
index 9f45498..02294ab 100644
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/CalendarSwap.java
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/CalendarSwap.java
@@ -142,6 +142,8 @@ public class CalendarSwap extends StringSwap<Calendar> {
 
 		@Override /* PojoSwap */
 		public String swap(BeanSession session, Calendar o) {
+			if (o == null)
+				return null;
 			o = setTimeZone(session, o);
 			return DatatypeConverter.printDateTime(o);
 		}
@@ -173,6 +175,8 @@ public class CalendarSwap extends StringSwap<Calendar> {
 
 		@Override /* PojoSwap */
 		public String swap(BeanSession session, Calendar o) {
+			if (o == null)
+				return null;
 			if (o.getTimeZone().getRawOffset() != 0) {
 				Calendar c = Calendar.getInstance(GMT);
 				c.setTime(o.getTime());
@@ -192,6 +196,8 @@ public class CalendarSwap extends StringSwap<Calendar> {
 
 		@Override /* PojoSwap */
 		public String swap(BeanSession session, Calendar o) {
+			if (o == null)
+				return null;
 			String s = super.swap(session, o);
 			return String.format("%s.%03d%s", s.substring(0, 19), o.get(Calendar.MILLISECOND), s.substring(19));
 		}
@@ -207,6 +213,8 @@ public class CalendarSwap extends StringSwap<Calendar> {
 
 		@Override /* PojoSwap */
 		public String swap(BeanSession session, Calendar o) {
+			if (o == null)
+				return null;
 			String s = super.swap(session, o);
 			return String.format("%s.%03d%s", s.substring(0, 19), o.get(Calendar.MILLISECOND), s.substring(19));
 		}
@@ -552,6 +560,8 @@ public class CalendarSwap extends StringSwap<Calendar> {
 	 */
 	@Override /* PojoSwap */
 	public String swap(BeanSession session, Calendar o) {
+		if (o == null)
+			return null;
 		return getDateFormat(session, o).format(o.getTime());
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9475ed21/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongSwap.java
index 11d4a03..9316280 100644
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongSwap.java
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongSwap.java
@@ -28,6 +28,8 @@ public class DateLongSwap extends PojoSwap<Date,Long> {
 	 */
 	@Override /* PojoSwap */
 	public Long swap(BeanSession session, Date o) {
+		if (o == null)
+			return null;
 		return o.getTime();
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9475ed21/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java
index b882dc0..fcaafe0 100644
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java
@@ -29,6 +29,8 @@ public class DateMapSwap extends PojoSwap<Date,Map> {
 	 */
 	@Override /* PojoSwap */
 	public Map swap(BeanSession session, Date o) {
+		if (o == null)
+			return null;
 		ObjectMap m = new ObjectMap();
 		m.put("time", o.getTime());
 		return m;

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9475ed21/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java
index b2fb0b0..3de5ba3 100644
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java
@@ -141,6 +141,8 @@ public class DateSwap extends StringSwap<Date> {
 
 		@Override /* PojoSwap */
 		public String swap(BeanSession session, Date o) {
+			if (o == null)
+				return null;
 			Calendar c = new GregorianCalendar();
 			c.setTime(o);
 			c = setTimeZone(session, c);
@@ -174,6 +176,8 @@ public class DateSwap extends StringSwap<Date> {
 
 		@Override /* PojoSwap */
 		public String swap(BeanSession session, Date o) {
+			if (o == null)
+				return null;
 			Calendar c = new GregorianCalendar();
 			c.setTime(o);
 			if (c.getTimeZone().getRawOffset() != 0) {
@@ -195,6 +199,8 @@ public class DateSwap extends StringSwap<Date> {
 
 		@Override /* PojoSwap */
 		public String swap(BeanSession session, Date o) {
+			if (o == null)
+				return null;
 			Calendar c = new GregorianCalendar();
 			c.setTime(o);
 			String s = super.swap(session, o);
@@ -212,6 +218,8 @@ public class DateSwap extends StringSwap<Date> {
 
 		@Override /* PojoSwap */
 		public String swap(BeanSession session, Date o) {
+			if (o == null)
+				return null;
 			Calendar c = new GregorianCalendar();
 			c.setTime(o);
 			String s = super.swap(session, o);
@@ -553,6 +561,8 @@ public class DateSwap extends StringSwap<Date> {
 	 */
 	@Override /* PojoSwap */
 	public String swap(BeanSession session, Date o) {
+		if (o == null)
+			return null;
 		return getDateFormat(session).format(o.getTime());
 	}
 


Mime
View raw message