[
https://issues.apache.org/jira/browse/SPARK-3944?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Prashant Sharma updated SPARK-3944:
-----------------------------------
Description:
The method tries to match a String (`uri.getScheme`) to obtain the result. The
value from `uri.getScheme` can be null.
Pattern matching using Regex when String value is null throws NPE in Scala
2.11.2. whereas it works in 2.10.4
Running the same code snippet gives different results
{noformat}
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java
1.7.0_60).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val pattern = "(.*)".r
pattern: scala.util.matching.Regex = (.*)
scala> val x:String = null
x: String = null
scala> x match { case pattern(x) => println("Success")
| case null => println("Fail")
| }
Fail
scala>
{noformat}
{noformat}
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java
1.7.0_60).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val pattern = "(.*)".r
pattern: scala.util.matching.Regex = (.*)
scala> val x:String = null
x: String = null
scala> x match { case pattern(x) => println("Success")
| case null => println("Fail")
| }
java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1234)
at java.util.regex.Matcher.reset(Matcher.java:308)
at java.util.regex.Matcher.<init>(Matcher.java:228)
at java.util.regex.Pattern.matcher(Pattern.java:1088)
at scala.util.matching.Regex.unapplySeq(Regex.scala:206)
... 47 elided
{noformat}
This happens because, In scala 2.11.2 "the unapply" tries to match the regex
even if the input is null. While in scala 2.10 it matches the correct case with
out unapplying.
was:
The method tries to match a String (`uri.getScheme`) to obtain the result. The
value from `uri.getScheme` can be null.
Pattern matching using Regex when String value is null throws NPE in Scala
2.11.2. whereas it works in 2.10.4
Running the same code snippet gives different results
{noformat}
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java
1.7.0_60).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val pattern = "(.*)".r
pattern: scala.util.matching.Regex = (.*)
scala> val x:String = null
x: String = null
scala> x match { case pattern(x) => println("Success")
| case null => println("Fail")
| }
Fail
scala>
{noformat}
{noformat}
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java
1.7.0_60).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val pattern = "(.*)".r
pattern: scala.util.matching.Regex = (.*)
scala> val x:String = null
x: String = null
scala> x match { case pattern(x) => println("Success")
| case null => println("Fail")
| }
java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1234)
at java.util.regex.Matcher.reset(Matcher.java:308)
at java.util.regex.Matcher.<init>(Matcher.java:228)
at java.util.regex.Pattern.matcher(Pattern.java:1088)
at scala.util.matching.Regex.unapplySeq(Regex.scala:206)
... 47 elided
{noformat}
> Utils.resolveURI is not consistent on upgrading scalaVersion to 2.11.2
> ----------------------------------------------------------------------
>
> Key: SPARK-3944
> URL: https://issues.apache.org/jira/browse/SPARK-3944
> Project: Spark
> Issue Type: Sub-task
> Reporter: Shiti Saxena
>
> The method tries to match a String (`uri.getScheme`) to obtain the result.
> The value from `uri.getScheme` can be null.
> Pattern matching using Regex when String value is null throws NPE in Scala
> 2.11.2. whereas it works in 2.10.4
> Running the same code snippet gives different results
> {noformat}
> Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java
> 1.7.0_60).
> Type in expressions to have them evaluated.
> Type :help for more information.
> scala> val pattern = "(.*)".r
> pattern: scala.util.matching.Regex = (.*)
> scala> val x:String = null
> x: String = null
> scala> x match { case pattern(x) => println("Success")
> | case null => println("Fail")
> | }
> Fail
> scala>
> {noformat}
> {noformat}
> Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java
> 1.7.0_60).
> Type in expressions to have them evaluated.
> Type :help for more information.
> scala> val pattern = "(.*)".r
> pattern: scala.util.matching.Regex = (.*)
> scala> val x:String = null
> x: String = null
> scala> x match { case pattern(x) => println("Success")
> | case null => println("Fail")
> | }
> java.lang.NullPointerException
> at java.util.regex.Matcher.getTextLength(Matcher.java:1234)
> at java.util.regex.Matcher.reset(Matcher.java:308)
> at java.util.regex.Matcher.<init>(Matcher.java:228)
> at java.util.regex.Pattern.matcher(Pattern.java:1088)
> at scala.util.matching.Regex.unapplySeq(Regex.scala:206)
> ... 47 elided
> {noformat}
> This happens because, In scala 2.11.2 "the unapply" tries to match the regex
> even if the input is null. While in scala 2.10 it matches the correct case
> with out unapplying.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]