JaroslavTulach at 09:31, 13 April 2011 - 2011-04-13 09:31:31

←Older revision Revision as of 09:31, 13 April 2011
Line 20: Line 20:
This is an interesting way to break many solid [[API]]s. The trick has been invented by the [[HPAPIFest09|HP guys]] when they played their [[HPAPIFest09]]. I am glad [[Ostrava]] discovered the magic as well. I am glad I could visit [[Ostrava]]'s JUG and talk about my two favorite topics: [[API]] design and [[NetBeans]] platform.
This is an interesting way to break many solid [[API]]s. The trick has been invented by the [[HPAPIFest09|HP guys]] when they played their [[HPAPIFest09]]. I am glad [[Ostrava]] discovered the magic as well. I am glad I could visit [[Ostrava]]'s JUG and talk about my two favorite topics: [[API]] design and [[NetBeans]] platform.
 +
 +
[[Category:Video]]

JaroslavTulach at 09:16, 13 April 2011 - 2011-04-13 09:16:42

←Older revision Revision as of 09:16, 13 April 2011
Line 4: Line 4:
[[Image:OstavaAJa.jpg|right|thumb]]
[[Image:OstavaAJa.jpg|right|thumb]]
-
I talked about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Here is the video from the presentation (only for Czech speakers):
+
I talked about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Here is the video taken during the JUG presentation. It is probably only useful for Czech speakers, as I spoke Czech. I have to mention that I admire the way the slides and the view of the speaker are merged together. Good job [[Ostrava]] JUG! I am glad I could stop by.
{{#ev:vimeo|21430542}}
{{#ev:vimeo|21430542}}

JaroslavTulach at 09:12, 13 April 2011 - 2011-04-13 09:12:07

←Older revision Revision as of 09:12, 13 April 2011
Line 1: Line 1:
[[Ostrava]] is 3rd largest town in Czech Republic. I visited [[wikipedia:Ostrava|Ostrava]]'s [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011.
[[Ostrava]] is 3rd largest town in Czech Republic. I visited [[wikipedia:Ostrava|Ostrava]]'s [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011.
-
[[Image:Ostrava-jug.jpg]]
+
[[Image:Ostrava-jug.jpg|right|thumb]]
 +
[[Image:OstavaAJa.jpg|right|thumb]]
-
I talked about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]].
+
I talked about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Here is the video from the presentation (only for Czech speakers):
 +
 
 +
{{#ev:vimeo|21430542}}
-
[[Image:OstavaAJa.jpg]]
 
Those who stopped by (and there was about 90 listeners) got a chance to win one copy of [[TheAPIBook]] by finding an answer to a simple quiz: Can you write a code that throws ''NullPointerException'' directly from the following ''Interval'' class?
Those who stopped by (and there was about 90 listeners) got a chance to win one copy of [[TheAPIBook]] by finding an answer to a simple quiz: Can you write a code that throws ''NullPointerException'' directly from the following ''Interval'' class?

JaroslavTulach at 12:26, 7 March 2011 - 2011-03-07 12:26:10

←Older revision Revision as of 12:26, 7 March 2011
Line 1: Line 1:
-
[[Ostrava]] is 3rd largest town in Czech Republic. I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]]. I am not sure what will be the final quiz to win [[TheAPIBook]], but I'd suggest following one: Can you write a code that throws ''NullPointerException'' directly from the following ''Interval'' class?
+
[[Ostrava]] is 3rd largest town in Czech Republic. I visited [[wikipedia:Ostrava|Ostrava]]'s [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011.
 +
 
 +
[[Image:Ostrava-jug.jpg]]
 +
 
 +
I talked about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]].
 +
 
 +
[[Image:OstavaAJa.jpg]]
 +
 
 +
Those who stopped by (and there was about 90 listeners) got a chance to win one copy of [[TheAPIBook]] by finding an answer to a simple quiz: Can you write a code that throws ''NullPointerException'' directly from the following ''Interval'' class?
<source lang="java" snippet="interval.api"/>
<source lang="java" snippet="interval.api"/>
-
I tried to follow all the [[good]] advices of [[TheAPIBook]]. I made the class final, I check for wrong arguments. My internal state is immutable. I guard myself against mutability of ''Date''. Is it really bullet proof code?
+
When writing the code I tried to follow all the [[good]] advices of [[TheAPIBook]]. I made the class final, I check for wrong arguments. My internal state is immutable. I guard myself against mutability of ''Date''. Is it enough to write bullet proof code?
Indeed it is not. As about five people during my [[Paradox]]es talk in [[Ostrava]] found out (and as few of you commented online), one can subclass ''Date'' and override ''clone'' method to return '''null''':
Indeed it is not. As about five people during my [[Paradox]]es talk in [[Ostrava]] found out (and as few of you commented online), one can subclass ''Date'' and override ''clone'' method to return '''null''':
Line 9: Line 17:
<source lang="java" snippet="interval.exploit"/>
<source lang="java" snippet="interval.exploit"/>
-
This is an interesting way to break many solid [[API]]s. The trick has been invented by the [[HPAPIFest09|HP guys]] when they played their [[HPAPIFest09]]. I am glad [[Ostrava]] discovered the magic as well.
+
This is an interesting way to break many solid [[API]]s. The trick has been invented by the [[HPAPIFest09|HP guys]] when they played their [[HPAPIFest09]]. I am glad [[Ostrava]] discovered the magic as well. I am glad I could visit [[Ostrava]]'s JUG and talk about my two favorite topics: [[API]] design and [[NetBeans]] platform.

JaroslavTulach at 19:22, 3 March 2011 - 2011-03-03 19:22:01

←Older revision Revision as of 19:22, 3 March 2011
Line 1: Line 1:
-
[[Ostrava]] is 3rd largest town in Czech Republic. I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]]. I am not sure what will be the final quiz to win [[TheAPIBook]], but I'd suggest following one: Can you write a code that throw ''NullPointerException'' directly from the following ''Interval'' class?
+
[[Ostrava]] is 3rd largest town in Czech Republic. I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]]. I am not sure what will be the final quiz to win [[TheAPIBook]], but I'd suggest following one: Can you write a code that throws ''NullPointerException'' directly from the following ''Interval'' class?
<source lang="java" snippet="interval.api"/>
<source lang="java" snippet="interval.api"/>

JaroslavTulach at 19:21, 3 March 2011 - 2011-03-03 19:21:15

←Older revision Revision as of 19:21, 3 March 2011
Line 1: Line 1:
[[Ostrava]] is 3rd largest town in Czech Republic. I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]]. I am not sure what will be the final quiz to win [[TheAPIBook]], but I'd suggest following one: Can you write a code that throw ''NullPointerException'' directly from the following ''Interval'' class?
[[Ostrava]] is 3rd largest town in Czech Republic. I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]]. I am not sure what will be the final quiz to win [[TheAPIBook]], but I'd suggest following one: Can you write a code that throw ''NullPointerException'' directly from the following ''Interval'' class?
-
<source lang="java">
+
<source lang="java" snippet="interval.api"/>
-
/** Quiz: Anyone can come up with a JUnit test to generate
+
-
* {@link NullPointerException} directly from the code of
+
-
* the <code>Interval</code> class?
+
-
*/
+
-
public final class Interval {
+
-
private final Date from, to;
+
-
+
-
/** Constructs interval between two dates.
+
-
*
+
-
* @param from the 'sooner' date
+
-
* @param to the 'later' date
+
-
* @throws IllegalArgumentException if <code>from</code> is not less then <code>to</code>
+
-
*/
+
-
public Interval(Date from, Date to) {
+
-
if (from == null) {
+
-
throw new IllegalArgumentException("'from' cannot be null!");
+
-
}
+
-
if (to == null) {
+
-
throw new IllegalArgumentException("'to' cannot be null!");
+
-
}
+
-
// shield us from Date's mutability
+
-
this.from = (Date) from.clone();
+
-
this.to = (Date)to.clone();
+
-
if (from.compareTo(to) >= 0) {
+
-
throw new IllegalArgumentException("'from' must be lower than 'to'!");
+
-
}
+
-
}
+
-
+
-
/** The length of the interval in milliseconds
+
-
*
+
-
* @return amount of milliseconds between 'from' and 'to' dates.
+
-
*/
+
-
public long getLength() {
+
-
return to.getTime() - from.getTime();
+
-
}
+
-
}
+
-
</source>
+
-
I followed all the advices of [[TheAPIBook]]. I made the class final, I check for wrong arguments. My internal state is immutable. I guard myself against mutability of ''Date''. Is it really write bullet proof code?
+
I tried to follow all the [[good]] advices of [[TheAPIBook]]. I made the class final, I check for wrong arguments. My internal state is immutable. I guard myself against mutability of ''Date''. Is it really bullet proof code?
 +
 
 +
Indeed it is not. As about five people during my [[Paradox]]es talk in [[Ostrava]] found out (and as few of you commented online), one can subclass ''Date'' and override ''clone'' method to return '''null''':
 +
 
 +
<source lang="java" snippet="interval.exploit"/>
 +
 
 +
This is an interesting way to break many solid [[API]]s. The trick has been invented by the [[HPAPIFest09|HP guys]] when they played their [[HPAPIFest09]]. I am glad [[Ostrava]] discovered the magic as well.

JaroslavTulach at 10:31, 2 March 2011 - 2011-03-02 10:31:16

←Older revision Revision as of 10:31, 2 March 2011
Line 1: Line 1:
-
I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]]. I am not sure what will be the final quiz to win [[TheAPIBook]], but I'd suggest following one: Can you write a code that throw ''NullPointerException'' directly from the following ''Interval'' class?
+
[[Ostrava]] is 3rd largest town in Czech Republic. I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]]. I am not sure what will be the final quiz to win [[TheAPIBook]], but I'd suggest following one: Can you write a code that throw ''NullPointerException'' directly from the following ''Interval'' class?
<source lang="java">
<source lang="java">

JaroslavTulach at 20:06, 1 March 2011 - 2011-03-01 20:06:04

←Older revision Revision as of 20:06, 1 March 2011
Line 40: Line 40:
</source>
</source>
-
I followed all the advices of [[TheAPIBook]]. I made the class final, I check for wrong arguments. I guard myself against mutability of ''Date''. Is it really write bullet proof code?
+
I followed all the advices of [[TheAPIBook]]. I made the class final, I check for wrong arguments. My internal state is immutable. I guard myself against mutability of ''Date''. Is it really write bullet proof code?

JaroslavTulach at 20:05, 1 March 2011 - 2011-03-01 20:05:24

←Older revision Revision as of 20:05, 1 March 2011
Line 5: Line 5:
* {@link NullPointerException} directly from the code of
* {@link NullPointerException} directly from the code of
* the <code>Interval</code> class?
* the <code>Interval</code> class?
-
*
 
-
* @author Jaroslav Tulach <jtulach@netbeans.org>
 
*/
*/
public final class Interval {
public final class Interval {

JaroslavTulach at 20:04, 1 March 2011 - 2011-03-01 20:04:58

←Older revision Revision as of 20:04, 1 March 2011
Line 1: Line 1:
-
I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]].
+
I'll be in [[wikipedia:Ostrava|Ostrava]] at [http://java.cz/article/czjug-ostrava-brezen-2011 JUG meeting] on Mar 2nd, 2011. I'll talk about [[paradox]]es, in a shorter version of the [[ParadoxesVideo]]. Stop by and get a chance to win [[TheAPIBook]]. I am not sure what will be the final quiz to win [[TheAPIBook]], but I'd suggest following one: Can you write a code that throw ''NullPointerException'' directly from the following ''Interval'' class?
 +
 
 +
<source lang="java">
 +
/** Quiz: Anyone can come up with a JUnit test to generate
 +
* {@link NullPointerException} directly from the code of
 +
* the <code>Interval</code> class?
 +
*
 +
* @author Jaroslav Tulach <jtulach@netbeans.org>
 +
*/
 +
public final class Interval {
 +
private final Date from, to;
 +
 +
/** Constructs interval between two dates.
 +
*
 +
* @param from the 'sooner' date
 +
* @param to the 'later' date
 +
* @throws IllegalArgumentException if <code>from</code> is not less then <code>to</code>
 +
*/
 +
public Interval(Date from, Date to) {
 +
if (from == null) {
 +
throw new IllegalArgumentException("'from' cannot be null!");
 +
}
 +
if (to == null) {
 +
throw new IllegalArgumentException("'to' cannot be null!");
 +
}
 +
// shield us from Date's mutability
 +
this.from = (Date) from.clone();
 +
this.to = (Date)to.clone();
 +
if (from.compareTo(to) >= 0) {
 +
throw new IllegalArgumentException("'from' must be lower than 'to'!");
 +
}
 +
}
 +
 +
/** The length of the interval in milliseconds
 +
*
 +
* @return amount of milliseconds between 'from' and 'to' dates.
 +
*/
 +
public long getLength() {
 +
return to.getTime() - from.getTime();
 +
}
 +
}
 +
</source>
 +
 
 +
I followed all the advices of [[TheAPIBook]]. I made the class final, I check for wrong arguments. I guard myself against mutability of ''Date''. Is it really write bullet proof code?