Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37920
| Path | csiph.com!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | j4n bur53 <janburse@fastmail.fm> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Unexpected Boxing Error at Runtime |
| Date | Fri, 5 Jan 2018 00:13:32 +0100 |
| Organization | albasani.net |
| Lines | 62 |
| Message-ID | <p2mcer$4vi$1@news.albasani.net> (permalink) |
| References | <p2ld0o$g4a$1@news.albasani.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.albasani.net T2vrUd4NJfmplM09pmBTevpdYcgztUGeq0NFDn5MBld86Jzg3TD6oTAOyCGXTswJZdH1Yx+h1D+yFP2O9hPBJg== |
| NNTP-Posting-Date | Thu, 4 Jan 2018 23:13:31 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="2A6A39quqoeYjIXyRvdS4pVXSnCbIVmqA9FH0Q+KC+gX6p2FdjhlFezfZt3vecWXX+hT3T8yma1XsM0KmxB0Y09SirmYat5nr93TMc043k9C1zjm8HezDAAP3KoBV4sI"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.1 |
| In-Reply-To | <p2ld0o$g4a$1@news.albasani.net> |
| Cancel-Lock | sha1:Gpx6ic/tjtOu54hmnb6RiNPyrAs= |
| Xref | csiph.com comp.lang.java.programmer:37920 |
Show key headers only | View raw
Dear All,
Thanks for the many responses. Woa,
the situation is quite contrived,
I looked at the byte code, and it seems
that it is translated as:
public int getNodesCount() {
synchronized (this) {
return (children != null ? Integer.valueOf(
children.size()) : null).intValue();
}
So ut seems the if-then-else to gets some type
widening from <nulltype> to Integer.
This makes it impossible for the compiler to spot
the error. Because usually this is spotted:
int foo = null;
Error: java: incompatible types: <nulltype>
cannot be converted to int
Best Regards
P.S.:
Here is the byte code of the if-then-else expression.
The compiler was javac 1.8.0_152:
GETFIELD DomElement.children : ListArray;
IFNULL L5
ALOAD 0
GETFIELD DomElement.children : ListArray;
INVOKEVIRTUAL ListArray.size ()I
INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
GOTO L6
L5
ACONST_NULL
L6
INVOKEVIRTUAL java/lang/Integer.intValue ()I
j4n bur53 schrieb:
> Dear All,
>
> By accident I used the following code:
>
> public int getNodesCount() {
> synchronized (this) {
> return (children != null ? children.size() : null);
> }
> }
>
> It has a subtle error, namely it returns a primitive
> data type, i.e. 'int', but uses automatic boxing.
>
> But that 'null' cannot be boxed to 'int', is only
> detected at runtime, and not during compile time.
>
> Is this a bug or feature of Java?
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unexpected Boxing Error at Runtime j4n bur53 <janburse@fastmail.fm> - 2018-01-04 15:16 +0100
Re: Unexpected Boxing Error at Runtime Eric Douglas <e.d.programmer@gmail.com> - 2018-01-04 07:04 -0800
Re: Unexpected Boxing Error at Runtime Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-01-04 10:13 -0500
Re: Unexpected Boxing Error at Runtime Eric Douglas <e.d.programmer@gmail.com> - 2018-01-04 08:01 -0800
Re: Unexpected Boxing Error at Runtime Marcel Mueller <news.5.maazl@spamgourmet.org> - 2018-01-04 18:33 +0100
Re: Unexpected Boxing Error at Runtime Kiwi User <martin@mydomain.invalid> - 2018-01-04 19:29 +0000
Re: Unexpected Boxing Error at Runtime Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-01-04 15:09 -0500
Re: Unexpected Boxing Error at Runtime Daniele Futtorovic <da.futt.news@laposte.net> - 2018-01-04 21:43 +0100
Re: Unexpected Boxing Error at Runtime Arne Vajhøj <arne@vajhoej.dk> - 2018-01-04 15:53 -0500
Re: Unexpected Boxing Error at Runtime Daniele Futtorovic <da.futt.news@laposte.net> - 2018-01-05 16:06 +0100
Re: Unexpected Boxing Error at Runtime Gene Wirchenko <genew@telus.net> - 2018-01-05 09:51 -0800
Re: Unexpected Boxing Error at Runtime Daniele Futtorovic <da.futt.news@laposte.net> - 2018-01-05 20:59 +0100
Re: Unexpected Boxing Error at Runtime Eric Douglas <e.d.programmer@gmail.com> - 2018-01-05 12:15 -0800
Re: Unexpected Boxing Error at Runtime Kiwi User <martin@mydomain.invalid> - 2018-01-05 21:52 +0000
Re: Unexpected Boxing Error at Runtime Gene Wirchenko <genew@telus.net> - 2018-01-08 11:13 -0800
Re: Unexpected Boxing Error at Runtime Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-01-05 16:27 -0500
Re: Unexpected Boxing Error at Runtime Daniele Futtorovic <da.futt.news@laposte.net> - 2018-01-06 00:06 +0100
Re: Unexpected Boxing Error at Runtime Kiwi User <martin@mydomain.invalid> - 2018-01-05 23:57 +0000
Re: Unexpected Boxing Error at Runtime Arne Vajhøj <arne@vajhoej.dk> - 2018-01-07 20:06 -0500
Re: Unexpected Boxing Error at Runtime bursejan@gmail.com - 2018-01-08 04:10 -0800
Re: Unexpected Boxing Error at Runtime bursejan@gmail.com - 2018-01-08 04:31 -0800
Re: Unexpected Boxing Error at Runtime Daniele Futtorovic <da.futt.news@laposte.net> - 2018-01-08 16:25 +0100
Re: Unexpected Boxing Error at Runtime Arne Vajhøj <arne@vajhoej.dk> - 2018-01-08 20:05 -0500
Re: Unexpected Boxing Error at Runtime bursejan@gmail.com - 2018-01-08 17:55 -0800
Re: Unexpected Boxing Error at Runtime Gene Wirchenko <genew@telus.net> - 2018-01-08 11:19 -0800
Re: Unexpected Boxing Error at Runtime Daniele Futtorovic <da.futt.news@laposte.net> - 2018-01-08 20:40 +0100
Re: Unexpected Boxing Error at Runtime Gene Wirchenko <genew@telus.net> - 2018-01-08 18:03 -0800
Re: Unexpected Boxing Error at Runtime Daniele Futtorovic <da.futt.news@laposte.net> - 2018-01-16 02:33 +0100
Re: Unexpected Boxing Error at Runtime bursejan@gmail.com - 2018-01-22 14:26 -0800
Re: Unexpected Boxing Error at Runtime bursejan@gmail.com - 2018-01-22 14:33 -0800
Re: Unexpected Boxing Error at Runtime Arne Vajhøj <arne@vajhoej.dk> - 2018-01-04 19:16 -0500
Re: Unexpected Boxing Error at Runtime Kiwi User <martin@mydomain.invalid> - 2018-01-05 12:17 +0000
Re: Unexpected Boxing Error at Runtime j4n bur53 <janburse@fastmail.fm> - 2018-01-05 00:13 +0100
Re: Unexpected Boxing Error at Runtime Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-01-05 11:05 -0500
Re: Unexpected Boxing Error at Runtime bursejan@gmail.com - 2018-01-06 06:18 -0800
csiph-web