Java bytecode LocalVariableTable contains duplicate entry for a single local variable - java-bytecode-asm

Here is my sample java code.
package com.test;
import javax.servlet.http.HttpServletRequest;
public class TestASMIns
{
public void process(HttpServletRequest request)
{
String userName;
if(request.getParameterMap().containsKey("username"))
{
userName = request.getParameter("username");
}
else
{
userName = "UNKNOWN";
}
System.out.println(userName);
}
}
In above example local variable userName declared inside of method body. AFAIK bytecode instruction for above code should contain only one LocalVariableNode for variable 'userName'(Since it is not declared within any inner scope/block). But bytecode instruction for LocalVariableTable contains duplicate entry for variable 'userName'. Can someone shed some light on this.
Here is the bytecode instructions: (generated using javap)
public void process(javax.servlet.http.HttpServletRequest);
descriptor: (Ljavax/servlet/http/HttpServletRequest;)V
flags: ACC_PUBLIC
Code:
stack=2, locals=3, args_size=2
0: aload_1
1: invokeinterface #16, 1 // InterfaceMethod javax/servlet/http/HttpServletRequest.getParameterMap:()Ljava/util/Map;
6: ldc #22 // String username
8: invokeinterface #24, 2 // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
13: ifeq 28
16: aload_1
17: ldc #22 // String username
19: invokeinterface #30, 2 // InterfaceMethod javax/servlet/http/HttpServletRequest.getParameter:(Ljava/lang/String;)Ljava/lang/String;
24: astore_2
25: goto 31
28: ldc #34 // String UNKNOWN
30: astore_2
31: getstatic #36 // Field java/lang/System.out:Ljava/io/PrintStream;
34: aload_2
35: invokevirtual #42 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
38: return
LineNumberTable:
line 10: 0
line 12: 16
line 13: 25
line 16: 28
line 18: 31
line 19: 38
LocalVariableTable:
Start Length Slot Name Signature
0 39 0 this Lcom/test/TestASMIns;
0 39 1 request Ljavax/servlet/http/HttpServletRequest;
25 3 2 userName Ljava/lang/String;
31 8 2 userName Ljava/lang/String;
StackMapTable: number_of_entries = 2
frame_type = 28 /* same */
frame_type = 252 /* append */
offset_delta = 2
locals = [ class java/lang/String ]
}

Related

Why is this switch statement only returning the default?

switch (numYears) {
case 10:
intsRate = 0.06;
break;
case 15:
intsRate = 0.05;
break;
case 30:
intsRate = 0.04;
break;
default:
intsRate = 0.08;
break;
}
return intsRate;
}
when the input of numYears is 10, 15, or 30 its returns the according double, but its only returning the defult. its part of a larger code but everything in that code is right this is the only part returning the wrong thing.

How can i fix the Element Implicity and No index Signature Error?

I am getting an Error in specialCodes[letter] saying Element implicitly has an 'any' type because expression of type 'string' can't be used to index type and No index signature with a parameter of type 'string' was found on type
import { Message, MessageEmbed } from "discord.js";
import BaseCommand from "../../utils/structures/BaseCommand";
import DiscordClient from "../../client/client";
export default class EmojifyCommand extends BaseCommand {
constructor() {
super("emojify", "fun", []);
/**
* #param {Client} client
* #param {Message} message
* #param {String[]} args
*/
}
async run(client: DiscordClient, message: Message, args: Array<string>) {
const embedSpecify = new MessageEmbed();
embedSpecify
.setColor("RED")
.setDescription("Please specify a text to translate!");
if (!args.length) return message.reply({ embeds: [embedSpecify] });
const specialCodes = {
0: ":zero:",
1: ":one:",
2: ":two:",
3: ":three:",
4: ":four:",
5: ":five:",
6: ":six:",
7: ":seven:",
8: ":eight:",
9: ":nine:",
"#": ":hash:",
"*": ":asterisk:",
"?": ":grey_question:",
"!": ":grey_exclamation:",
" ": " ",
};
const text = args
.join(" ")
.toLowerCase()
.split("")
.map((letter) => {
if (/[a-z]/g.test(letter)) {
return `:regional_indicator_${letter}:`;
} else if (specialCodes[letter]) {
return `${specialCodes[letter]}`;
}
return letter;
})
.join("");
message.reply(text);
}
}
You have mixed types of keys in specialCodes and you need to help TS to understand how to get values from there. Something like this:
const specialCodes: Record<number | string, string> = {
0: ":zero:",
1: ":one:",
2: ":two:",
3: ":three:",
4: ":four:",
5: ":five:",
6: ":six:",
7: ":seven:",
8: ":eight:",
9: ":nine:",
"#": ":hash:",
"*": ":asterisk:",
"?": ":grey_question:",
"!": ":grey_exclamation:",
" ": " ",
};

NestJS async functions in a for loop

my idea is to create a microservice that:
A- Reads everything from a collection
B- Does a loop with all that data
C- Inside the loop, each time calls another collection to get reference data from each item
ex:
#Cron('*/10 * * * * *')
async runEvery10Seconds() {
console.log("log 1");
let allDataFromCollection= await this.findAllData();
for (let i = 0; i != allDataFromCollection.length; i++) {
let item1Id = this.referencedb(allDataFromCollection[i].item1value);
let item2Id = this.referencedb(allDataFromCollection[i].item2value);
let item3Id = this.referencedb(allDataFromCollection[i].item3value);
// then I create a JSON with this new data
let data = {
item1 = item1Id ,
item2 = item2Id,
item3 = item3Id
}
this.sendHttpPost(data);
}//close for
}
Things never reach the HttpPost and the only output is the first console log ("log 1") in loop, until the code terminates with
5: 00007FF7428063BD v8::SharedArrayBuffer::Externalize+781
6: 00007FF7426B084C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516
7: 00007FF7426BBB8A v8::internal::Heap::ProtectUnprotectedMemoryChunks+1258
8: 00007FF7426B8D39 v8::internal::Heap::PageFlagsAreConsistent+2457
9: 00007FF7426AD961 v8::internal::Heap::CollectGarbage+2033
10: 00007FF7426ABB65 v8::internal::Heap::AllocateExternalBackingStore+1317
11: 00007FF7426C5E06 v8::internal::Factory::AllocateRaw+166```

Recycle and GetNextDocument / GetNextCategory in NotesViewNavigator?

How do I do a recycle for GetNextDocument or GetNextCategory in a NotesViewNavigator? Neither takes an argument so you can't use the conventional method of using a temp variable to pre get the next document like you might in a view.
I suppose the solution would be to just use getNext with an argmenumnt but can GetNextDocument / GetNextCategory still be used?
The error I am getting is on line 20. Without the recycle the code runs fine. From what I understand recycle destroys the object so I can understand the reason for the error. My questition is if there is another way around this?
[TypeError] Exception occurred calling method NotesViewNavigator.getNextDocument() null
occurs on line 20
1: var viewName = "vwParticipantsProjectIDEquipmentIDUsername";
2:
3:
4: var v:NotesView = database.getView(viewName);
5: var nav:NotesViewNavigator = v.createViewNavFromCategory(sessionScope.get("ExportProjectID"));
6:
7:
8: var viewEnt:NotesViewEntry = nav.getFirstDocument();
9:
10: while (viewEnt != null)
11: {
12:
13: if (viewEnt.isDocument())
14: {
15:
16: var doc:NotesDocument = viewEnt.getDocument();
17: }
18:
19: viewEnt.recycle();
20: viewEnt = nav.getNextDocument();
21: }
This is the pattern that I tend to use:
var documentEntry = nav.getFirstDocument();
while( documentEntry != null ){
var nextDocumentEntry = nav.getNextDocument();
// do stuff
documentEntry.recycle();
documentEntry = nextDocumentEntry;
}
Why don't you try to apply the old pattern like this:
var viewName = "vwParticipantsProjectIDEquipmentIDUsername",
v:NotesView = database.getView(viewName),
nav:NotesViewNavigator = v.createViewNavFromCategory(sessionScope.get("ExportProjectID")),
viewEnt:NotesViewEntry = nav.getFirstDocument(),
tmp:NotesViewEntry;
while (viewEnt !== null)
{
if (viewEnt.isDocument())
{
var doc:NotesDocument = viewEnt.getDocument();
}
tmp = viewEnt;
viewEnt = nav.getNextDocument();
tmp.recycle();
}
I did not test it, but I guess that works...

Raspberry Pi running Meteor bundle throws call stack exception

I've installed Node.js on a Raspberry Pi and I'm attempting to run the Meteor.js leaderboard example on it. I've bundled it and copied it to the Pi. I've set my MONGO_URL and npm installed Fiber (after some trouble). When I try to run:
$ node main.js
I get a Maximum call stack size exceeded exception.
/home/pi/bundle/server/server.js:143
}).run();
^
RangeError: Maximum call stack size exceeded
I ran the command with --trace and got this:
/home/pi/bundle/server/server.js:143
1: GetLineNumber+56(this=0x4e92928d <JS Object>, 0x26693f79 <JSMessageObject>) {
2: ScriptLocationFromPosition+64(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 0x4e9080a1 <true>) {
3: ScriptLineFromPosition+60(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636) {
4: ScriptLineCount+40(this=0x26693f25 <a Script value = 0x4e953839 <Script>>) {
4: } -> 151
4: SUB+48(this=151, 1) {
4: } -> 150
4: ADD+52(this=0, 150) {
4: } -> 150
4: SAR+48(this=150, 1) {
4: } -> 75
4: ADD+52(this=75, 1) {
4: } -> 76
4: SUB+48(this=146, 1) {
4: } -> 145
4: SUB+48(this=146, 1) {
4: } -> 145
3: } -> 142
3: SUB+48(this=142, 1) {
3: } -> 141
3: ADD+52(this=4630, 1) {
3: } -> 4631
3: SUB+48(this=4642, 1) {
3: } -> 4641
3: charAt+48(this=0x3735a0cd <Very long string[4703]>, 4641) {
3: } -> 0x37324625 <String[1]: ;>
3: SUB+48(this=4636, 4631) {
3: } -> 5
3: ADD+52(this=142, 0) {
3: } -> 142
3: new SourceLocation+40(this=0x26694b99 <a SourceLocation>, 0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 142, 5, 4631, 4642) {
3: } -> 0x4e908091 <undefined>
2: } -> 0x26694b99 <a SourceLocation>
2: ADD+52(this=142, 1) {
2: } -> 143
1: } -> 143
/home/pi/bundle/server/server.js:143
1: GetSourceLine+56(this=0x4e92928d <JS Object>, 0x26693f79 <JSMessageObject>) {
2: ScriptLocationFromPosition+64(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 0x4e9080a1 <true>) {
3: ScriptLineFromPosition+60(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636) {
4: ScriptLineCount+40(this=0x26693f25 <a Script value = 0x4e953839 <Script>>) {
4: } -> 151
3: } -> 142
3: charAt+48(this=0x3735a0cd <Very long string[4703]>, 4641) {
3: } -> 0x37324625 <String[1]: ;>
3: new SourceLocation+40(this=0x26694ce5 <a SourceLocation>, 0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 142, 5, 4631, 4642) {
3: } -> 0x4e908091 <undefined>
2: } -> 0x26694ce5 <a SourceLocation>
2: SourceLocationRestrict+60(this=0x26694ce5 <a SourceLocation>, 0x4e908091 <undefined>, 0x4e908091 <undefined>) {
3: SUB+48(this=78, 10) {
3: } -> 68
3: SUB+48(this=4642, 4631) {
3: } -> 11
2: } -> 0x4e908091 <undefined>
2: SourceLocationSourceText+40(this=0x26694ce5 <a SourceLocation>) {
3: substring+64(this=0x3735a0cd <Very long string[4703]>, 4631, 4642) {
3: } -> 0x26694d29 <String[11]: }).run();>
2: } -> 0x26694d29 <String[11]: }).run();>
1: } -> 0x26694d29 <String[11]: }).run();>
}).run();
1: GetPositionInLine+56(this=0x4e92928d <JS Object>, 0x26693f79 <JSMessageObject>) {
2: ScriptLocationFromPosition+64(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 0x4e9080b1 <false>) {
3: ScriptLineFromPosition+60(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636) {
4: ScriptLineCount+40(this=0x26693f25 <a Script value = 0x4e953839 <Script>>) {
4: } -> 151
3: } -> 142
3: charAt+48(this=0x3735a0cd <Very long string[4703]>, 4641) {
3: } -> 0x37324625 <String[1]: ;>
3: new SourceLocation+40(this=0x26694d71 <a SourceLocation>, 0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 142, 5, 4631, 4642) {
3: } -> 0x4e908091 <undefined>
2: } -> 0x26694d71 <a SourceLocation>
2: SourceLocationRestrict+60(this=0x26694d71 <a SourceLocation>, 0x4e908091 <undefined>, 0x4e908091 <undefined>) {
2: } -> 0x4e908091 <undefined>
2: SUB+48(this=4636, 4631) {
2: } -> 5
1: } -> 5
1: GetPositionInLine+56(this=0x4e92928d <JS Object>, 0x26693f79 <JSMessageObject>) {
2: ScriptLocationFromPosition+64(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 0x4e9080b1 <false>) {
3: ScriptLineFromPosition+60(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636) {
4: ScriptLineCount+40(this=0x26693f25 <a Script value = 0x4e953839 <Script>>) {
4: } -> 151
3: } -> 142
3: charAt+48(this=0x3735a0cd <Very long string[4703]>, 4641) {
3: } -> 0x37324625 <String[1]: ;>
3: new SourceLocation+40(this=0x26694e7d <a SourceLocation>, 0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 142, 5, 4631, 4642) {
3: } -> 0x4e908091 <undefined>
2: } -> 0x26694e7d <a SourceLocation>
2: SourceLocationRestrict+60(this=0x26694e7d <a SourceLocation>, 0x4e908091 <undefined>, 0x4e908091 <undefined>) {
2: } -> 0x4e908091 <undefined>
1: } -> 5
^
1: ToString+40(this=0x4e92928d <JS Object>, 0x4e908091 <undefined>) {
1: } -> 0x373080bd <String[9]: undefined>
1: getter+40(this=0x26693e85 <a RangeError>) {
2: +40(this=0x4e908091 <undefined>, 0x4e96824d <a RangeError>) {
3: FormatMessage+72(this=0x4e908091 <undefined>, 0x26694ed5 <JSMessageObject>) {
4: ADD+52(this=0, 1) {
4: } -> 1
4: ADD+52(this=1, 0) {
4: } -> 1
4: ADD+52(this=0, 2) {
4: } -> 2
4: FormatString+64(this=0x4e908091 <undefined>, 0x2669611d <JS array[1]>, 0x26694ed5 <JSMessageObject>) {
5: ADD+52(this=0x373082e5 <String[0]: >, 0x59c1f9cd <String[32]: Maximum call stack size exceeded>) {
5: } -> 0x59c1f9cd <String[32]: Maximum call stack size exceeded>
5: ADD+52(this=1, 0) {
5: } -> 1
4: } -> 0x59c1f9cd <String[32]: Maximum call stack size exceeded>
3: } -> 0x59c1f9cd <String[32]: Maximum call stack size exceeded>
2: } -> 0x59c1f9cd <String[32]: Maximum call stack size exceeded>
1: } -> 0x59c1f9cd <String[32]: Maximum call stack size exceeded>
RangeError: 1: getter+40(this=0x26693e85 <a RangeError>) {
1: } -> 0x59c1f9cd <String[32]: Maximum call stack size exceeded>
Maximum call stack size exceeded
The last place I can track this problem to is in the file:
app/packages/mongo-livedata/mongo_driver.js
at around line 10:
var MongoDB = __meteor_bootstrap__.require('mongodb');
I have the latest npm installed (1.1.50) and have npm installed mongodb globally. I am pointing to a hosted mongodb at mongolab.com. I've created a simple test to connect and insert a few records. It uses the exact same url that I'm trying to use for Meteor and it works as expected:
var connect = require('mongodb').connect;
var url = 'mongodb://<user>:<password>#<cloud_id>.mongolab.com:<port>/<database>';
connect(url, function(err, db) {
db.collection('test', function(err, collection) {
// Insert 3 records
for(var i = 0; i < 3; i++) {
collection.insert({'a':i});
}
});
});
I don't really understand the trace message but it seems like FormatString call is what triggers the exception. Any suggestions?
Update:
I've debugged this a little more and isolated the problem to the loading of a specific mongodb module shown here as filename. From stepping through it for a while, it seems like the module is recursively including itself.
break in module.js:311
Watchers:
0: path = ...
1: parent = ...
2: filename = "/home/pi/bundle/server/node_modules/mongodb/lib/mongodb/connection/repl_set.js"
308 var hadException = true;
309
310 try {
311 module.load(filename);
312 hadException = false;
313 } finally {
314 if (hadException) {
315 delete Module._cache[filename];
316 }
317 }
debug>
< RangeError: Maximum call stack size exceeded
program terminated
Unfortunately I don't think that MongoDB currently supports the ARM architecture see https://jira.mongodb.org/browse/SERVER-1811
However you could run Mongo on another machine and have the drivers connect to that or if you really wanted it to run on your raspberry PI you could try an unofficial build
Indeed, as pointed out by Wilfred Knievel, MongoDB currently does not support the ARM architecture. I have made available the (unofficial) binaries of MongoDB so that you do not need to recompile them (as it is quite a long/tricky procedure). These binaries, together with a sample program (in C) are available here
not sure if you now our meteor universal fork at
https://github.com/4commerce-technologies-AG/meteor
but we covered a number of issues there. Also some errors about fibers and mongo. Please take a look at the (closed) issues and check out the pre-built binaries on bintray at
https://bintray.com/4commerce-technologies-ag/meteor-universal/arm-dev-bundles/1.3.3.1/view#files/arm_dev_bundles
You may also use the node and the mongo tgz just to bring up the services.
Hope that helps
Tom

Resources